I am trying to time a simple Python method using timeit but I keep getting the following error
File "<timeit-src>", line 6, in inner
KeyError: 'tree'
The code, as shown below, creates a 'tree' object and then I attempt to pass that object in the Timer object. I guess this is where the problem is.
Note that if instead I pass binarytree.mkthing(0,10) to Timer the code works. However doing this calls mkthing at every pass. I want to call it only once and then reuse it.
How should I go about doing that?
if __name__=="__main__":
tree = mkthing(0,10)
t1=timeit.Timer("binarytree.traverse_asc(locals()['tree'],binarytree.printout)","import binarytree")
print t1.repeat(2, 3)