About Measuring Code Execution Time

Check how long it takes to run a snippet of code in seconds like this:

1
2
3
4
5
6
7
import time

start_time = time.perf_counter()
# here goes code in question...
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time} s")

Tips and Tricks Programming Performance Python 3