I am trying to compute the time my program takes to execute but sometimes it works fine and sometimes I get the following error:
ImportError: cannot import name 'N' from '__main__'
N = number
t = timeit.Timer(
"computeArea(N, 4)",
"from __main__ import computeArea, N")
computeTime = t.timeit(1)
print(computeTime)
What do you think of just importing
timeand measuring the time before and aftercomputeArearuns? Honestly speaking, this chunk of code looks pretty funky from a Python style perspective. Measuring the time yourself is easy, and can be easily modified for more interesting examples (say, taking the average time by timing the same code dozens of times).