I do not know this is my first attempt and it is almost same fast as wc on my pc:

int main(string[] args)
{
    import std.stdio : writeln, writefln, File;
    import std.array : uninitializedArray;

    auto f = File("data");
    size_t c = 0;
    auto buffer = uninitializedArray!(ubyte[])(1024);
    foreach (chunk; f.byChunk(buffer))
    {
        foreach (ch; chunk)
            if (ch == '\n')
                ++c;
    }
    writeln(c);
    return 0;
}

And I belive it could be faster when iopipe is used


Dne 30.5.2017 v 22:02 Nitram via Digitalmars-d-learn napsal(a):
After reading https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i was wondering how fast one can do a simple "wc -l" in D.

So i made a couple short implementations and found myself confronted with slow results compared to "/usr/bin/wc -l".

How would a implementation look like in D, which is fast?


Reply via email to