Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 23 18:37:17 UTC 2019


On Thu, May 23, 2019 at 06:20:23PM +0000, kdevel via Digitalmars-d-learn wrote:
> On Thursday, 23 May 2019 at 09:44:15 UTC, Cym13 wrote:
[...]
> > To go fast, read/write bigger chunks.
> 
> Or use rawWrite instead of write (reduces the runtime to about 1.6 s).
> When using write time is IMHO spent in unicode processing and/or
> locking. Or write more characters at a time. The code below takes 60
> ms to complete.

If you're on Linux, writing a bunch of zeroes just to create a large
file is a waste of time. Just use the kernel's sparse file feature:

	https://www.systutorials.com/136652/handling-sparse-files-on-linux/

The blocks won't actually get allocated until you write something to
them, so this beats any write-based method of creating a file filled
with zeroes -- probably by several orders of magnitude. :-P


T

-- 
It is not the employer who pays the wages. Employers only handle the money. It is the customer who pays the wages. -- Henry Ford


More information about the Digitalmars-d-learn mailing list