How do I get time of a Python program's execut

2018-12-31 19:31发布

I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.

I've looked at the timeit module, but it seems it's only for small snippets of code. I want to time the whole program.

标签: python time
25条回答
一个人的天荒地老
2楼-- · 2018-12-31 20:09
import time

start_time = time.clock()
main()
print time.clock() - start_time, "seconds"

time.clock() returns the processor time, which allows us to calculate only the time used by this process (on Unix anyway). The documentation says "in any case, this is the function to use for benchmarking Python or timing algorithms"

查看更多
登录 后发表回答