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

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

    time.clock()

    Deprecated since version 3.3: The behavior of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well-defined behavior.

    time.perf_counter()

    Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide.

    time.process_time()

    Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process. It does not include time elapsed during sleep.

    start = time.process_time()
    ... do something
    elapsed = (time.process_time() - start)
    

提交回复
热议问题