[Python-Dev] Startup time
Raymond Hettinger
python@rcn.com
Wed, 7 May 2003 19:55:03 -0400
> Guido, any chance you can quickly run the above two through the thirty-leven
> versions of Python you have laying about so we can narrow this down or
> refute my faulty memory? I've seen some recent posts by you which had
> performance data as far back as 1.3. I tried with 2.1, 2.2 and CVS but saw
> no discernable differences within versions:
>
> % python ~/local/bin/timeit.py -s'def f(): pass' 'import math; f()'
> 100000 loops, best of 3: 7.44 usec per loop
> % python ~/local/bin/timeit.py -s'def f(): import math' 'f()'
> 100000 loops, best of 3: 7.6 usec per loop
>
> % python2.2 ~/local/bin/timeit.py -s'def f(): pass' 'import math; f()'
> 100000 loops, best of 3: 9.19 usec per loop
> % python2.2 ~/local/bin/timeit.py -s'def f(): import math' 'f()'
> 100000 loops, best of 3: 9.05 usec per loop
>
> % python2.1 ~/local/bin/timeit.py -s'def f(): pass' 'import math; f()'
> 100000 loops, best of 3: 9.16 usec per loop
> % python2.1 ~/local/bin/timeit.py -s'def f(): import math' 'f()'
> 100000 loops, best of 3: 9.12 usec per loop
I don't think timeit.py helps here. It works by substituting *both*
the setup and statement inside a compiled function.
So, *none* of the above timings show the effect of a top level import
versus one that is inside a function. It does compare 1 deep nesting
to 2 levels deep.
So, you'll likely have to roll your own minature timer if you want
a straight answer.
Raymond Hettinger