Python Glossary Русский

Python 3.7+timefunction

time.thread_time_ns()

clocks and timing

CPU time of the current thread as an integer number of nanoseconds — the thread_time() variant without float rounding.

Syntax

time.thread_time_ns() -> int

Same rules as thread_time(): take the difference within one thread, sleep and waiting are not counted. Do not mix it with thread_time() in one difference — seconds and nanoseconds differ by 10**9, and nothing will raise.

Examples

import time
t0 = time.thread_time_ns()
sum(range(100_000))
d = time.thread_time_ns() - t0
print(d >= 0, type(d).__name__)  # → True int

See also

Open in the full glossarydocs.python.orgReport an inaccuracy