loop performance in global namespace (python-2.6.1)

Duncan Booth duncan.booth at invalid.invalid
Thu Mar 12 14:50:25 EDT 2009


Poor Yorick <org.python.pythonlist at pooryorick.com> wrote:

> In the following snippet, the loop in the global namespace takes twice
> as long as the loop in the function namespace.  Why?
> 
Accessing global variables is generally slower than accessing local 
variables. Locals are effectively stored in a vector so the bytecode can go 
straight to the first local or the second local. Globals require a 
dictionary lookup.



More information about the Python-list mailing list