Python 3.7+timefunction
time.monotonic_ns()
clocks and timing
The same monotonic clock as monotonic(), but as an integer number of nanoseconds — without float rounding.
Syntax
time.monotonic_ns() -> int
Differences are integers, so they add up in counters and compare for equality without accumulated float error. Do not mix the _ns and plain versions in one difference: one is in seconds, the other in nanoseconds, and an error of 10**9 does not raise — it silently corrupts the result.
Examples
import time
a = time.monotonic_ns()
b = time.monotonic_ns()
print(b - a >= 0, type(b - a).__name__) # → True int
See also
Open in the full glossarydocs.python.orgReport an inaccuracy