performance problem in python 2.2

Jeff Davis jdavis at empires.org
Fri Jul 26 22:16:36 EDT 2002


Paul Rubin wrote:

> Fernando Perez <fperez528 at yahoo.com> writes:
>> 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.
> 
> Global variables are accessed by a dict lookup in the global environment.
> Local variables are accessed by looking directly at the appropriate
> slot in the local stack frame.

Ahh... more good information! Thanks so much, and to Tim as well for 
pointing that out initially. 

I've learned a lot about python today :)

Regards,
        Jeff









More information about the Python-list mailing list