all Python 3timeitfunction
timeit.default_timer()
timing
The clock timeit uses by default; since Python 3.3 it is time.perf_counter.
Syntax
start = timeit.default_timer(); ...; elapsed = timeit.default_timer() - start
It is not a separate function but a reference to time.perf_counter, so a single value is meaningless; only the difference of two calls matters. It includes sleep and time spent by other processes; for pure CPU time pass time.process_time as timer=.
Examples
import time, timeit
print(timeit.default_timer is time.perf_counter) # → True
start = timeit.default_timer()
total = sum(range(10_000))
elapsed = timeit.default_timer() - start
print(elapsed >= 0) # → True
print(elapsed) # → ? секунды
See also
Open in the full glossarydocs.python.orgReport an inaccuracy