Python 3.3+timefunction
time.get_clock_info()
clocks and timing
Information about a clock by name: resolution, monotonicity, whether it can be adjusted, and which system call backs it.
Syntax
time.get_clock_info(name)
The name is a string without the module prefix: 'time', 'monotonic', 'perf_counter', 'process_time', 'thread_time'; anything else raises ValueError. adjustable=True for 'time' is exactly why you should not measure intervals with it. resolution is the step of readings, not accuracy: a clock with a 1 ns step can still be off by milliseconds.
Examples
import time
print(time.get_clock_info('monotonic').monotonic) # → True
print(time.get_clock_info('time').adjustable) # → True
print(time.get_clock_info('perf_counter').implementation) # → ? clock_gettime(CLOCK_MONOTONIC)
try:
time.get_clock_info('clock')
except ValueError as e:
print(e) # → unknown clock
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy