bug in my gcc? bug in my code? both?
http://files.minthos.com/code/speedtest_doubles_wtf.cpp
Somehow, it manages to “optimize” a function that results in the array of doubles being zeroed out into taking 2.6 seconds on my q6600, instead of the 33 ms the more complex function takes to fill the array with something somewhat meaningful.
I’d be interested in knowing if others get similar results, and if so, if anyone can explain what’s going on.. And also figure out what causes the huge difference between integer and floating-point performance (especially when compiling without optimization).
Line 99:
is partially initializing
floats[]effectively with floating point garbage. The rest remain zero. This stems from replacing the floats with integer bitmaps and then subsequently interpreting them as doubles. Perhaps the overflows and underflows are affecting performance? To test, I changed the random number seed to a constant 1000 for reproducibility and got these results:Repeating after replacing the memcpy with a proper assignment so type conversion can occur should prevent floating point boundary conditions:
The modified program, still with constant 1000 as random seed, provides these results:
This is an older PC, circa 2004, otherwise lightly loaded.
Looks like that made matters slower. Fewer zeroes to do arithmetic with perhaps? That is what many random bit patterns look like. Or values like 0.0000000000000000000000000382652. Once that is added to, say 0.1, the low bits tend to be removed.