Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Lie Ryan
John Machin wrote: On Mar 13, 2:41 am, spir wrote: Le Thu, 12 Mar 2009 11:13:33 -0400, Kent Johnson s'exprima ainsi: Because local name lookup is faster than global name lookup. Local variables are stored in an array in the stack frame and accessed by index. Global names are stored in a dict

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread John Machin
On Mar 13, 2:41 am, spir wrote: > Le Thu, 12 Mar 2009 11:13:33 -0400, > Kent Johnson s'exprima ainsi: > > > Because local name lookup is faster than global name lookup. Local > > variables are stored in an array in the stack frame and accessed by > > index. Global names are stored in a dict and a

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Scott David Daniels
Poor Yorick wrote: In the following snippet, the loop in the global namespace takes twice as long as the loop in the function namespace. Why? Locals are known to have no outside interaction, and so are not looked up by name. your code could have a thread that did, global counter

Re: loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Duncan Booth
Poor Yorick 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 s