Python time clock() Method
Description
Python 3.8 has removed the clock() methodYou can use thetime.perf_counter()ortime.process_time()method instead.
The Python time clock() function returns the current CPU time as a floating-point number of seconds. It is used to measure the time consumed by different programs and is more useful than time.time().
Note that its meaning differs on different systems. On UNIX systems, it returns "process time", which is a floating-point number expressed in seconds (timestamp). On Windows, the first call returns the actual time the process has been running. Calls after the first return the running time from the first call to the present. (It is actually based on QueryPerformanceCounter() on WIN32, which is more precise than millisecond representation.)
Syntax
clock() method syntax:
time.clock()
Parameters
- NA。
Return Value
This function has two functions:
On the first call, it returns the actual time the program has been running;
From the second call onward, it returns the time interval from the first call to this call.
On win32 systems, this function returns real time (wall time), while on Unix/Linux it returns CPU time.
Example
The following example demonstrates how to use the clock() function:
Example
import time
def procedure():
time.sleep(2.5)
# measure process time
t0 = time.clock()
procedure()
print time.clock() - t0, "seconds process time"
# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"
The output of the above example is:
3.3e-05 seconds process time 2.50329995155 seconds wall timeOther Extensions