I am trying to figure out how long it takes to execute a Python instruction, so I looked online and found that the standard library provides a module called timeit that is designed to do just that:
import timeit def foo():
However, this causes an error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in dotime File "/usr/local/lib/python2.6/timeit.py", line 193, in timeit timing = self.inner(it, self.timer) File "<timeit-src>", line 6, in inner NameError: global name 'foo' is not defined
I'm still new to Python, and I don't quite understand all the problems it has, but I don't know why this snippet doesn't work. Any thoughts?
scope python timeit
Kyle Cronin Feb 15 '09 at 23:15 2009-02-15 23:15
source share