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

Daniel Kozak kozzi11 at gmail.com
Thu May 23 21:19:34 UTC 2019


On Thu, May 23, 2019 at 11:06 PM Daniel Kozak <kozzi11 at gmail.com> wrote:

> On Thu, May 23, 2019 at 11:10 AM BoQsc via Digitalmars-d-learn <
> digitalmars-d-learn at puremagic.com> wrote:
>

> https://matthias-endler.de/2017/yes/
>

So this should do it

void main()
{
    import std.range : array, cycle, take;
    import std.stdio;
    immutable buf_size = 8192;
    immutable buf = "\x00".cycle.take(buf_size).array;
    auto cnt = 50_000_000 / buf_size;
    immutable tail = "\x00".cycle.take(50_000_000 % buf_size).array;
    File file = File("test.txt", "w");
    while(cnt--)
        file.rawWrite(buf);
    file.rawWrite(tail);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20190523/b20a1efb/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list