performance problem in python 2.2

Fernando Perez fperez528 at yahoo.com
Fri Jul 26 21:18:43 EDT 2002


Mark Day wrote:

> 
> Maybe you missed Tim's comment about putting the loop in a function to
> make it faster.  Using that trick made the Python version as fast as
> Perl on my machine.
> 

Nice. I did miss that indeed. I guess in general this doesn't matter to me as 
I almost never have any top-level code, but it's something to be aware of. 

Out of curiosity, why does this happen? I understand looking up global 
variables when in a function being expensive, since you first must go through 
the local dict (and fail). But when the code is itself global and there's no 
other scope in sight, why is it any slower? In a sense, for global code 
'everything is local', so I don't quite understand why the difference.

cheers,

f.




More information about the Python-list mailing list