Describe
The Python Time Clock () function returns the current CPU times as a number of seconds in floating-point count. It is more useful than time.time () to measure the time spent on different programs.
It is important to note that the meanings are different on different systems. On a UNIX system, it returns "process time", which is a floating-point number (timestamp) in seconds. In Windows, the first call returns the actual time that the process is running. The second subsequent call is the elapsed time since the first call to the present . (actually based on QueryPerformanceCounter () on WIN32, which is more accurate than milliseconds)
Grammar
Clock () method syntax:
Time. Clock()
return value
The function has two functions,
At the time of the first call, the actual time of the program running is returned;
After the second call, the time interval from the first call to the call is returned
Under the Win32 system, this function returns the real time (wall times), while the CPU time is returned under Unix/linux.
Instance
The following example shows how the clock () function is used:
ImportTimeDefProcedure():Time.Sleep(2.5)# Measure Process TimeT0=Time.Clock()Procedure()print Time. () - T0 "seconds process time" # measure wall time< Span class= "PLN" >t0 = Time. () procedure () Time. () - T0 "seconds Wall time"
The result of the above example output is:
0.0 seconds Process time2.50023603439 seconds Wall time
Python Time Clock () method