Python Measure Elapsed Time

February 24, 2021
import time

start_time = time.perf_counter()

time.sleep(5)

elapsed_time = time.perf_counter() - start_time

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. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.