howto count lines - fast
Nitram via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 31 13:37:00 PDT 2017
I am glad to see this participation on this issue :)
The hints about trying another compiler and std.mmfile turned out
to be very effective.
Even this simple code is faster then my systems "wc -l" now:
>void main() {
> import std.stdio;
> writeln(lcs("benchmark.dat"));
>}
>
>size_t lcs(string filename) {
> import std.mmfile;
> auto f = new MmFile(filename);
> auto data = cast(ubyte[]) f[];
> size_t c = 0;
> foreach(ref i ; data) {
> if (i == '\n') c++;
> }
> return c;
>}
>time wc -l ./benchmark.dat
>10500000 ./benchmark.dat
>wc -l ./benchmark.dat 0,06s user 0,03s system 99% cpu 0,089
>total
>time ./lcs
>10500000
>./lcs 0,05s user 0,01s system 99% cpu 0,061 total
More information about the Digitalmars-d-learn
mailing list