Python3 - Using timeit to measure script execution

2019-08-19 04:34发布

问题:

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?