loop performance in global namespace (python-2.6.1)
sjmachin at lexicon.net
Thu Mar 12 23:03:58 CET 2009
On Mar 13, 2:41 am, spir <denis.s... at free.fr> wrote:
> Le Thu, 12 Mar 2009 11:13:33 -0400,
> Kent Johnson <ken... at tds.net> 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__()).
> ? I thought this was mainly because a name has first to be searched (unsuccessfully) locally before a global lookup is launched.
No; for locals, the name resolution is done at COMPILE time.
> Also, are locals really stored in an array?
Yes. You seem surprised ... the technique of locals (and args) being
referenced at run time by a constant offset from a frame pointer
register has been around for at least 40 years.
> How does lookup then proceed? Is it a kind of (name,ref) sequence?
There is no name lookup at run time. The values of locals (and args)
are obtained by simple array access.
More information about the Python-list