Use of the clock () method for processing time in Python, pythonclock
The clock () method returns the current processor time, in seconds representing a floating point number on Unix. The accuracy depends on the C function with the same name, but in any case, this is an algorithm function that is used for benchmarking Python or timing.
In Windows, this function is returned because the first call of this function has been suspended for several seconds. As a floating point number, it is based on the Win32 function QueryPerformanceCounter.
Syntax
The following is the syntax of the clock () method:
Time. clock ()
Parameters
Return Value
This method returns the current processor time as a floating point number in UNIX seconds, and in Windows it indicates that the first call to this function is called in the past clock second, as a floating point number.
Example
The following example shows how to use the clock () method.
#! /Usr/bin/pythonimport timedef procedure (): time. sleep (2.5) # measure process timet0 = time. clock () procedure () print time. clock ()-t0, "seconds process time" # measure wall timet0 = time. time () procedure () print time. time ()-t0, "seconds wall time"
When we run the above program, it will produce the following results:
0.0 seconds process time2.50023603439 seconds wall time
Note: not all systems can measure the actual processing time. In such a system (including Windows), because of the start time of the program.