Speed-up for loops

Stefan Behnel stefan_ml at behnel.de
Wed Sep 8 00:48:16 EDT 2010


BartC, 08.09.2010 03:45:
> Getting back to the OP's code again (trivial and pointless as it might
> seem), I got these results:
>
> C (gcc 3.4.5 -O3) 0.8 secs
> C (DMC-o) 2.3 secs
> C (lccwin32 -O) 2.9 secs
>[...]
> I've seen LuaJIT in action. It's timing for this test is 1.5 secs:
> forget being only 10x slower than C, it's faster than some C versions!
> (I'm sure it must be cheating somewhere...)

Sure it does. C is statically compiled, while LuaJIT is a JIT compiler. It 
unjustly uses *runtime* information to compile the code. You can get a 
similar advantage with some C compilers by using profile based optimisation.

BTW, I wonder why the code takes a whole 0.8 seconds to run in your gcc 
test. Maybe you should use a newer GCC version. It shouldn't take more than 
a couple of milliseconds (for program startup, OS calls, etc.), given that 
the output is a constant.

Stefan




More information about the Python-list mailing list