loop in python

Daniel Dittmar daniel.dittmar at sap.corp
Mon Aug 22 17:26:06 CEST 2005


km wrote:
> Why is it that the implementation of empty loop so slow in python when compared to perl ? 
[...]
> Is python runtime slow at all aspects when compared to perl ? 

No

> I really wonder what makes python slower than perl ? 

It could be that the Perl compiler recognizes such a for loop and emits 
special code (e.g. an integer loop variable that gets incremented). 
Python creates an xrange object and then has the overhead of 1000 next() 
calls.

You should benchmark other features before jumping to conclusions: calls 
to functions, calls to methods, calls to inherited methods.

Others will probably chime in with arguments whether such micro 
benchmarks are a useful indication of the speed a complete program at all.

> Is there any proposal to make python faster in future versions ? 

Yes in the general case, probably no in this specific case.


Daniel



More information about the Python-list mailing list