Python3 Att Time Clock
# Python3.x Python3 time clock() Method
* * *
## Description
Python 3.8 has removed the clock() method. You can use the **time.perf_counter()** or **time.process_time()** methods as alternatives.
The Python time clock() function returns the current CPU time in seconds as a floating-point number. It is used to measure the time taken by different programs and is more useful than time.time().
Please note that its meaning varies on different systems. On UNIX systems, it returns the "process time", which is a floating-point number (timestamp) expressed in seconds. On Windows, the first call returns the actual running time of the process. Subsequent calls return the time elapsed since the first call. (Actually, it is based on QueryPerformanceCounter() on Win32, which is more precise than millisecond representation)
## Syntax
The clock() method syntax:
time.clock()
## Parameters
* NA.
## Return Value
This function has two functionalities:
On the first call, it returns the actual running time of the program;
On subsequent calls after the second, it returns the time interval from the first call to the current call.
On win32 systems, this function returns the real time (wall time), while on Unix/Linux it returns the CPU time.
## Example
The following example demonstrates the usage of the clock() function:
#!/usr/bin/python3import time def procedure(): time.sleep(2.5)# time.clock t0 = time.clock() procedure()print (time.clock() - t0)# time.time t0 = time.time() procedure()print (time.time() - t0)
The output of the above example is:
5.000000000000143e-052.5020556449890137
YouTip