On Mon, Apr 12, 2010 at 2:51 AM, Leonardo Giordani <leonardo.giord...@treuropa.com> wrote: <top-level module code snipped> > which runs in about 80 seconds on my local hardware (mean of multiple > execution) > If I move the whole code into a function and call this latter the execution > time drops to about 45 seconds. > > What is the reason of this improvement?
The top-level module namespace (i.e. global scope) is implemented using a dictionary (i.e. hash table). Names in local function scope instead use precalculated offsets into an array. The latter is faster than the former, hence the speed difference. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list