Sergey Gromov wrote:
Sat, 22 Nov 2008 20:14:37 -0500, bearophile wrote:
Can you or someone else run that little D code, so you can tell me if
my timings are right?
Tested your code using DMD 2.019. You are right. The #1 is about 30
times slower than #2: 10s against 0,3s on my laptop. I've also tried to
replace CRT malloc with GC malloc in #2 and it ran just a bit slower--I
would say around 4%--even though I didn't call hasNoPointers() anywhere.
The really weird part is, if I comment out the "init mats randomly" loop
in #1, it becomes twice as slow, i.e. 20s against the original 10s. I
don't get it.
I think what happens is that the speed of FP arithmetic depends on the
values of the operands. Whenever a NaN is involved everything gets a lot
slower (tested that). Also, I believe (without having tested it) that
multiplying with zero is faster than multiplying nonzero numbers.
Andrei