Using Python “timeit” to time functionsPosted: September 12, 2008
Python’s timeit module is not intuitive for me.
def foo(x): return x+1 import timeit timeit.Timer("foo(1)","from __main__ import foo")
was a godsend!
Reading this hint contradicted my blithe statement to friend this morning that “the only time __main__ appears in user code is to determine when a script is being run form the command line”. Such ignorance and folly!