byLine and readln performance with LDC

Jon D via digitalmars-d-ldc digitalmars-d-ldc at
Tue Dec 8 17:34:33 PST 2015

I'm seeing dramatically slower runtime performance using byLine 
and readln when compiling with LDC than with DMD. Has anyone seen 
this behavior?


import std.stdio: File, KeepTerminator, writeln;

void main(string[] args) {
     if (args.length != 2) {
         writeln("Provide exactly one filename");

     auto inputStream = args[1].File();
     size_t lc = 0;
     foreach (line; inputStream.byLine(KeepTerminator.yes)) {

Using a 1.7gb, 37 million line file:
  - ldc2 (-release -O):  37 seconds
  - dmd (-release -O):   4 seconds

Same results with readln rather than byLine.  However, byChunk is 
fast, even with small chunks like 40 bytes.

This is using:  Mac OS X (10.10.5);  DMD 2.068; LDC 0.16.1


More information about the digitalmars-d-ldc mailing list