On Wednesday, 24 July 2013 at 07:20:16 UTC, Peter Alexander wrote:
This comment is worrying:
"Can you try D version without std.random, and use srand and
rand from std.c.stdlib? I think it should be almost same speed
as C version ;-)"
"Wow! Just tried that, and this brings the running time of the
DMD-compiled version to 0.770s from 1.290, the GDC-compiled
version from 1.060 to 0.680s, and the LDC version to 0.580s
from 0.710s. Meaning the LDC version is on par with the
Clang-compiled C version and just slightly beats the
GCC-compiled C one! There really should be a warning note in
the std.random library documentation that for
performance-critical code the C stdlib random generator is a
better choice."
Is this just because RNGs are value types? It's literally
causing bad press for D, so this needs to be high on the
priority list.
RNGs should be passed by ref so if that isn't happening, there
might be a speed hit (there will also be noticeable statistical
problems). But the posted code just used rndGen and didn't pass
anything.
C stdlib rand() is fast but has terrible statistical performance.
Mersenne Twister is fast relative to its (high) statistical
quality, but will still be slower than something designed purely
for speed without concern for quality.
It'd be interesting to see how the speeds go if Xorshift was used
in place of Mersenne Twister, that should give a big speed boost
while still having high statistical quality.