Python Glossary Русский

Python 3.7+timefunction

time.process_time_ns()

clocks and timing

The process CPU time as an integer number of nanoseconds — the same as process_time(), without float rounding.

Syntax

time.process_time_ns() -> int

A nanosecond unit does not make the clock finer: the OS often accounts CPU time in scheduler ticks, so a short piece of code may show a difference of 0. Measure noticeable chunks of work with it, not a single line.

Examples

import time
t0 = time.process_time_ns()
sum(i * i for i in range(200_000))
print(time.process_time_ns() - t0 >= 0)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy