I have a python script than can sort files and i want to know how long it takes to run.
i searched for a module that's names time but it didnt work and it asked me to put a real time.
I have a python script than can sort files and i want to know how long it takes to run.
i searched for a module that's names time but it didnt work and it asked me to put a real time.
You can calculate execution time like that:
import time
start_time = time.time()
# your script here
end_time = time.time()
execution_time = end_time - start_time
print("Execution time:", execution_time, "seconds")
I prefer to use time.perf_counter()
if we are talking about timing code:
from time import perf_counter
# Get the start 'time'
t1 = perf_counter()
# Some complex time-consuming function
for i in range(10**9):
pass
# Get the end 'time'
t2 = perf_counter()
# Now you subtract the start time from the end time and you have your elapsed time:
print("Elapsed time:",t2-t1)
Check the documentation here: https://docs.python.org/3/library/time.html#time.perf_counter