Timing a function object versus timeit

Carl Banks pavlovevidence at gmail.com
Sat Nov 4 03:02:37 CET 2006

Steven D'Aprano wrote:
> The timeit module is ideal for measuring small code snippets; I want to
> measure large function objects.
> Because the timeit module takes the code snippet argument as a string, it
> is quite handy to use from the command line, but it is less convenient for
> timing large pieces of code or when working in the interactive
> interpreter. E.g. variations on this *don't* work:
> Do others have other suggestions or techniques they use?

Python 2.4.3 (#2, Jun 19 2006, 12:51:44)
[GCC 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(x):
...     return x+1
>>> import timeit
>>> timeit.Timer("foo(1)","from __main__ import foo")

Carl Banks

More information about the Python-list mailing list