howto count lines - fast
Jordan Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 30 13:37:44 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list