About Python execution speed

Chris Rebert clp2 at rebertia.com
Mon Apr 12 12:24:55 CEST 2010

On Mon, Apr 12, 2010 at 2:51 AM, Leonardo Giordani
<leonardo.giordani at 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.


More information about the Python-list mailing list