How do I get time of a Python program's execution?
execution-time, python, time
Solution
The simplest way in Python:
import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
This assumes that your program takes at least a tenth of second to run.
Prints:
--- 0.764891862869 seconds ---
Problem
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.
Related problems
- How do I profile a Python script?
- How do I measure execution time of a command on the Windows command line?
- Time python scripts using IPython magic
- Find if 24 hrs have passed between datetimes
- How can I get millisecond and microsecond-resolution timestamps in Python?
- Python subprocess with /usr/bin/time: How can I capture timing information, but ignore all other output?