import time
import timeit
start = timeit.timeit()
time.sleep(5)
end = timeit.timeit()
time_elapsed = end - start
print(end)
print(time_elapsed)
print(start)
Outputs:
0.018255482330552297
-0.00033663523232263515
0.018592117562874932
import time
import timeit
start = timeit.timeit()
time.sleep(5)
end = timeit.timeit()
time_elapsed = end - start
print(end)
print(time_elapsed)
print(start)
Outputs:
0.018255482330552297
-0.00033663523232263515
0.018592117562874932
As the documentation clearly says:
This… returns the time it takes to execute the main statement a number of times, measured in seconds as a float.
Meanwhile, notice that this is the elapsed time to run the main statement—that is, nothing at all, in your case. It's not a timestamp or anything like that. So subtracting end - start
doesn't give you anything useful—it's the difference in elapsed time for two different runs of a no-op.