logo

Python Time Clock() Method


Show

Description

Python time process clock() revisits the existing processor time as a hovering point number articulated in seconds on Unix. The exactitude depends on that of the C meaning of the same first name, however, in any casing, this is the purpose to employ for benchmarking Python or timing algorithms.

On Windows, this purpose revisits wall-clock seconds passed while the first call to this purpose, as a floating-point numeral, anchored in the Win32 function QueryPerformanceCounter.

Syntax

Following is the syntax for asctime() method:

Parameters

  • NA

Return Value

This method returns the current processor time as a floating-point number expressed in seconds on Unix and in Windows it returns wall-clock seconds elapsed since the first call to this function, as a floating-point number.

Example

The following example shows the usage of clock() method.

#!/usr/bin/python
import time

def procedure():
   time.sleep(2.5)

# measure process time
t0 = time.clock()
procedure()
print time.clock(), "seconds process time"

# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"

When we run the above program, it produces the following result:

0.0 seconds process time
2.50023603439 seconds wall time

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.