问题
Let's say I have a python script script.py
and I want to measure the execution time of it just as if I put the whole script in quotation marks and used:
from timeit import Timer
t = Timer(stmt='THE WHOLE SCRIPT')
print(t.timeit())
I could do this by editing script.py
, but I'd like not to. What I want is a second script measure.py
, which can be executed like ./measure.py script.py
, which will basically do the above with any script as an argument.
How could I approach writing such a script measure.py
?
来源:https://stackoverflow.com/questions/47877966/python3-using-timeit-to-measure-script-execution-time-externally