How do I get time of a Python program's execution?

后端 未结 30 1663
甜味超标
甜味超标 2020-11-22 02:20

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

30条回答
  •  死守一世寂寞
    2020-11-22 02:47

    To use metakermit's updated answer for Python 2.7, you will require the monotonic package.

    The code would then be as follows:

    from datetime import timedelta
    from monotonic import monotonic
    
    start_time = monotonic()
    end_time = monotonic()
    print(timedelta(seconds=end_time - start_time))
    

提交回复
热议问题