On Thursday, 19 March 2015 at 16:59:36 UTC, Ola Fosheim Grøstad
wrote:
On Thursday, 19 March 2015 at 00:42:51 UTC, weaselcat wrote:
On Wednesday, 18 March 2015 at 12:59:17 UTC, bearophile wrote:
High level constructs in D are often slower than low-level
code, so in some cases you don't want to use them.
I actually found that LDC does an _amazing_ job of optimizing
high level constructs and converting "low level" code to
higher level functional code resulted in minor speedups in a
lot of cases.
(Other performance benefits include the algorithm primitives
being extensively optimized in phobos.)
If the code/compiler generates suboptimal code in the first
place then improvements can be somewhat random. But if you
write code with good cache locality, filling the pipeline
properly then there is no alternative to going low level.
Btw, take a look at this:
http://stackoverflow.com/questions/28922323/improving-line-wise-i-o-operations-in-d
That's really bad marketing...
python:
time python2 wc.py
enwiki-latest-pages-articles1.xml-p000000010p000010000
There are 1245473 lines
python2 wc.py
enwiki-latest-pages-articles1.xml-p000000010p000010000 0.21s
user 0.08s system 99% cpu 0.294 total
wc -l:
time wc -l enwiki-latest-pages-articles1.xml-p000000010p000010000
1245472 enwiki-latest-pages-articles1.xml-p000000010p000010000
wc -l enwiki-latest-pages-articles1.xml-p000000010p000010000
0.05s user 0.02s system 96% cpu 0.072 total
iterative version:
ldc -O5 -inline -release -boundscheck=off wc.d
time ./wc
There are 1245473 lines.
./wc enwiki-latest-pages-articles1.xml-p000000010p000010000
0.59s user 0.07s system 99% cpu 0.661 total
functional version:
writeln("There are ",
(cast(string)read(args[1])).splitter('\n').array.length, "
lines.");
ldc -O5 -inline -release -boundscheck=off wc.d
time ./wc enwiki-latest-pages-articles1.xml-p000000010p000010000
There are 1245473 lines.
./wc enwiki-latest-pages-articles1.xml-p000000010p000010000
0.04s user 0.08s system 98% cpu 0.125 total
ahem
I actually found that LDC does an _amazing_ job of optimizing
high level constructs and converting "low level" code to
higher level functional code resulted in minor speedups in a
lot of cases.