all Python 3osfunction
os.times
os — process
Return a named tuple of process times (user/system/…, 5 fields).
Syntax
os.times()
The user and system fields are CPU time, not wall-clock time: a process waiting for input accumulates little of it. On Windows only user and system are filled in; the other fields are zero. For timing code time.perf_counter is handier, and for the current process's CPU time time.process_time.
Examples
import os
print(len(os.times())) # → 5
print(os.times().user) # → процессорное время в пользовательском режиме, в секундах, например 0.09
c0 = os.times().user
sum(range(10 ** 6)) # → нагружаем процессор, сам результат не нужен
print(round(os.times().user - c0, 2)) # → прирост CPU-времени за цикл, например 0.03
print(os.times().elapsed) # → на Unix — секунды от некоторой точки в прошлом; на Windows известны только user и system, остальные поля равны 0.0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy