I recently noticed the following about the timeit
python module:
On my machine the lines:
from timeit import Timer
t = Timer(stmt='a = 2**3**4')
print("This took {:.3f}s to execute.".format(t.timeit()))
will produce:
This took 0.017s to execute.
On the other hand writing a file test.py:
#!/usr/bin/env python3
a = 2**3**4
and calling:
from timeit import Timer
t = Timer(stmt='import test')
print("This took {:.3f}s to execute.".format(t.timeit()))
will produce:
This took 0.126s to execute.
And I'm wondering how I can test the execution time of test.py
without changing the file itself. How can I work around importing the file (and therefore loosing time).