Python Glossary Русский

Python 3.3+timefunction

time.process_time()

clocks and timing

CPU time of the current process in seconds: how much processor time the program actually used, excluding sleep and waiting.

Syntax

time.process_time() -> float

Do not confuse it with perf_counter(): time.sleep(1) or waiting on the network adds a second to perf_counter() and almost nothing here. All threads of the process are summed, so a multithreaded program can show more process_time() than wall time. Child processes (subprocess, multiprocessing) are not counted.

Examples

import time
cpu0, wall0 = time.process_time(), time.perf_counter()
time.sleep(0.1)
print(time.perf_counter() - wall0 >= 0.1)  # → True
print(time.process_time() - cpu0 < 0.05)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy