performance problem in python 2.2

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Fri Jul 26 21:43:27 EDT 2002


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.



More information about the Python-list mailing list