<div dir="ltr">On Sat, Jul 25, 2015 at 7:14 PM, Andrei Alexandrescu via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 7/25/15 8:19 AM, Johan Holmberg via Digitalmars-d wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<br>
<br>
I am trying to port a program I have written earlier to D. My previous<br>
versions are in C++ and Python. I was hoping that a D version would be<br>
similar in speed to the C++ version, rather than similar to the Python<br>
version. But currently it isn't.<br>
<br>
Part of the problem may be that I haven't learned the idiomatic way to<br>
do things in D. One such thing is perhaps: how do I read large text<br>
files in an efficient manner in D?<br>
<br>
Currently I have created a little test-program that does the same job as<br>
the UNIX-command "wc -lc", i.e. counting the number of lines and<br>
characters in a file. The timings I get in different languages are:<br>
<br>
D:           15s<br>
C++:       1.1s<br>
Python:   3.7s<br>
Perl:        2.9s<br>
</blockquote>
<br></span>
I think this harkens back to the problem discussed here:<br>
<br>
<a href="http://stackoverflow.com/questions/28922323/improving-line-wise-i-o-operations-in-d/29153508" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/28922323/improving-line-wise-i-o-operations-in-d/29153508</a><br>
<br>
As I discuss there, the performance bug has been fixed for 2.068. With your code:<br>
<br>
$ time wc -l <(repeat 1000000 echo hello)<br>
 1000000 /dev/fd/11<br>
wc -l <(repeat 1000000 echo hello)  0.11s user 2.35s system 54% cpu 4.529 total<br>
$ time ./test.d <(repeat 1000000 echo hello)<br>
 1000000 6000000 /dev/fd/11<br>
./test.d <(repeat 1000000 echo hello)  0.73s user 1.76s system 64% cpu 3.870 total<br>
<br>
The compilation was flag free (no -O -inline -release etc).<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
Andrei<br>
<br>
</font></span></blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks, my question seems like a carbon copy of the Stack Overflow article :) Somehow I had missed it when googling.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I download a dmd 2.068 beta, and re-tried with my input file: now the D program takes 1.6s (a 10x improvement).</div><div class="gmail_extra"><br></div><div class="gmail_extra">/johan</div><div class="gmail_extra"><br></div></div>