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

2009-03-12 Thread Kent Johnson
On Thu, Mar 12, 2009 at 11: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

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

2009-03-12 Thread spir
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 accessed with dict access > (dict.__getitem__

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

2009-03-12 Thread Kent Johnson
On Thu, Mar 12, 2009 at 8:13 AM, 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? Because local name lookup is faster than global name lookup. Local variables are stored in an array in the stack fr

[Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread Poor Yorick
In the following snippet, the loop in the global namespace takes twice as long as the loop in the function namespace. Why? limit = 5000 def f1(): counter = 0 while counter < limit: counter += 1 time1 = time.time() f1() print(time.time() - time