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

后端 未结 30 2136
甜味超标
甜味超标 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 03:05

    from time import time
    start_time = time()
    ...
    end_time = time()
    time_taken = end_time - start_time # time_taken is in seconds
    hours, rest = divmod(time_taken,3600)
    minutes, seconds = divmod(rest, 60)
    

提交回复
热议问题