Why is stdin.byLine.writeln so slow?

Jyxent via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 13 13:48:14 PDT 2014


I've been playing around with D and noticed that:

stdin.byLine.writeln

takes ~20 times as long as:

foreach(line; stdin.byLine) writeln(line);

I asked on IRC and this was suggested:

stdin.byLine(KeepTerminator.yes).copy(stdout.lockingTextWriter)

which is slightly faster than the foreach case.

It was suggested that there is something slow about writeln 
taking the input range, but I'm not sure I see why.  If I follow 
the code correctly, formatRange in std.format will eventually be 
called and iterate over the range.


More information about the Digitalmars-d-learn mailing list