how fast is Python?
jepler at unpythonic.net
Thu Aug 21 20:58:53 CEST 2003
I don't know what Mark Carter wanted to measure either, but I'd like to
mention that when I compile "a.cpp" on my system with the flags Alex
used, the generated code doesn't even include any floating-point
arithmetic. The compiler was able to deduce that X was dead after the
loop, and that its computation had no side-effects. I'm a little
surprised that the compiler didn't completely remove the loop, but it's
still there. "i" isn't there either, instead there's a counter that
begins at 107, decrements and terminates the loop when it reaches -1.
And if I use the directive to unroll loops, the logic is the same except
that the counter decreases by 18 each time instead of 1.
... and anyway, this modified code (which does actually compute X when
compiled on my system) aborts with a floating point overflow error.
As far as I can tell, your program would be computing a value on the
order of 10^(3x10^31)...
Ah, the joy of writing the proverbial good benchmark.
fpu_control_t __fpu_control = _FPU_IEEE &~ _FPU_MASK_OM;
double X = 0.5;
for(int i = 0; i < 108; i++)
X = 1 + X * X;
Y = X;
More information about the Python-list