Most people mean CPU time when they say "execution time" and for that you would use time.process_time()
. In your case, however, where all you are doing is sleeping between two consecutive calls, it would produce for the second call a return value of approximately 0. If you want elapsed time and are rounding to 2 places, I wouldn't think it would matter if you are using time.time
or time.perf_counter
. But perf_counter
provides the higher resolution when you do care about that.
import time
t0 = time.time()
t0a = time.perf_counter()
t0b = time.process_time()
time.sleep(1)
t1 = time.time()
t1a = time.perf_counter()
t1b = time.process_time()
print(round(t1 - t0, 2), round(t1a - t0a, 2), t1b - t0b)
Prints:
1.0 1.0 0.015625