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

后端 未结 30 2320
甜味超标
甜味超标 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:57

    Similar to the response from @rogeriopvl I added a slight modification to convert to hour minute seconds using the same library for long running jobs.

    import time
    start_time = time.time()
    main()
    seconds = time.time() - start_time
    print('Time Taken:', time.strftime("%H:%M:%S",time.gmtime(seconds)))
    

    Sample Output

    Time Taken: 00:00:08
    

提交回复
热议问题