On Tuesday, 30 May 2017 at 20:02:38 UTC, Nitram wrote:
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?

Not sure if this is the fastest, but anyway

void main(){
    import std.file : read;
    import std.conv : to;
    import std.algorithm : count;

    auto data = cast(ubyte[])read("somefile.txt");
    auto lc = data.count('\n'.to!ubyte);
}

Jordan

Reply via email to