On Wednesday, 11 November 2015 at 13:32:00 UTC, perlancar wrote:
While I am quite impressed with how easy I was able to write D,
I am not so impressed with the performance. Using rdmd (build
20151103), the D program runs in 17.127s while the Perl version
runs in 11.391s (so the D version is quite a bit *slower* than
Perl's). While using gdc (Debian 4.9.2-10), I am able to run it
in 3.988s (only about 3x faster than Perl's version).
I understand that string processing (concatenation, allocation)
is quite optimized in Perl, I was wondering if the D version
could still be sped up significantly?
Did you try rdmd -O -noboundscheck -release yourscript.d ?
You should try using appender!string rather than concatenate
(http://dlang.org/phobos/std_array.html#.Appender) using capacity
(http://dlang.org/phobos/std_array.html#.Appender.capacity) to
improve performace.
You should also switch from for to foreach.
Andrea