Latest web development tutorials

Python time clock () method

description

Python time clock () function is the number of seconds to return the current floating-point computations of CPU time. Different procedures used to measure the time-consuming than time.time () more useful.

Note that this requires different meanings in different systems. On UNIX systems, it returns a "process of time", it is floating point (time stamp) in seconds. In WINDOWS, the first call, the return is the actual running time of the process. And called a second time after the first call since the running time now. (Actually a WIN32 on QueryPerformanceCounter (), based on more accurate than milliseconds)

grammar

clock () method syntax:

time.clock()

parameter

  • NA.

return value

This function has two functions,

In the first call, the return is the actual running time of the program;

To call a second time after the return is the time since the first call, the call to the interval

Under win32 system, this function returns the real time (wall time), while in Unix / Linux returns the CPU time.

Examples

The following example shows the clock () function to use:

#!/usr/bin/python
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 above example output is:

0.0 seconds process time
2.50023603439 seconds wall time