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
I was having the same problem in many places, so I created a convenience package horology
. You can install it with pip install horology
and then do it in the elegant way:
from horology import Timing
with Timing(name='Important calculations: '):
prepare()
do_your_stuff()
finish_sth()
will output:
Important calculations: 12.43 ms
Or even simpler (if you have one function):
from horology import timed
@timed
def main():
...
will output:
main: 7.12 h
It takes care of units and rounding. It works with python 3.6 or newer.