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

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

    Timeit is a class in Python used to calculate the execution time of small blocks of code.

    Default_timer is a method in this class which is used to measure the wall clock timing, not CPU execution time. Thus other process execution might interfere with this. Thus it is useful for small blocks of code.

    A sample of the code is as follows:

    from timeit import default_timer as timer
    
    start= timer()
    
    # Some logic
    
    end = timer()
    
    print("Time taken:", end-start)
    

提交回复
热议问题