You can use module timeit to measure elapsed time in Python. This is particularly helpful to measure time for a Python execution as shown in the below example –
1 2 3 4 5 6 7 |
import time from timeit import default_timer as timer start = timer() time.sleep(5) ## Sleep for 5 seconds end = timer() print(end - start) ## Returns 5.0085995 |