How to pass in argument to timeit.Timer

silverburgh.meryl at gmail.com silverburgh.meryl at gmail.com
Sat Apr 28 20:48:11 CEST 2007


Hi,

I have a function in my python like this:
def callFunc(line, no):
      # some code

And I want to do a performance test like this:
 for line in f:
        for i in range(int(count)):
            t1 = timeit.Timer("callFunc(line, i)","from __main__
import callFunc")
            r1 = t1.timeit();
            print r1;

but when I run it, it can't recognize the parameter 'line' and 'i',
can you please tell me how to fix it? i get this error:

 File "/usr/lib/python2.4/timeit.py", line 161, in timeit
    timing = self.inner(it, self.timer)
  File "<timeit-src>", line 6, in inner
NameError: global name 'line' is not defined

Thank you.




More information about the Python-list mailing list