why are these exec times so different?

Jeff Epler jepler at unpythonic.net
Wed Dec 17 08:09:18 EST 2003


On Wed, Dec 17, 2003 at 01:09:06AM +0000, r.e.s. wrote:
> Should one expect the following execution times 
> to be so different? ... 

No reason comes immediately to mind.  Usually,
    def f():
        suite
    f()
will run a little faster than
    suite
because LOAD_FAST variable references, which are used inside functions
for function-scope variables but not at the module top-level scope, are
speedier than LOAD_NAME and LOAD_GLOBAL codes.

So it's safe to say that the real reason for this huge difference in the
favor of the "global scope" version lies in your code somewhere.  The
part you didn't post.

Jeff





More information about the Python-list mailing list