Python Glossary Русский

Python 3.7+Linux · macOStimefunction

time.clock_gettime_ns()

POSIX clocks

The reading of the system clock clk_id as an integer number of nanoseconds. Unix only: Linux and macOS.

Syntax

time.clock_gettime_ns(clk_id) -> int

Prefer it to clock_gettime() for CLOCK_REALTIME: seconds since the epoch are large there and a float loses hundreds of nanoseconds. The result is an int in nanoseconds, never mix it with the float version in one difference. Windows lacks it; the portable equivalents are time_ns() and monotonic_ns().

Examples

import time
a = time.clock_gettime_ns(time.CLOCK_MONOTONIC)  # → ? на Windows AttributeError
b = time.clock_gettime_ns(time.CLOCK_MONOTONIC)
print(b >= a, type(b).__name__)  # → True int

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy