Wednesday, July 15, 2020

Python Time clock() Method with example

Hello guys! Welcome back to another section of my tutorial on Python. In this tutorial guide, we are going to be studying about Python's Time clock() method.

The Python's Time clock() function returns the current processor time as a floating point number expressed in seconds on Unix Os. The precision is dependent on that of the C function of same name, but in any case, this is the function to use for benchmarking Python or timing algorithms.

On Windows Os, this function returns wall-clock seconds elapsed since the first call of this method, as a floating point number, based on the Win32 function QueryPerformaceCounter.   


The following below is the syntax for Python Time clock() method -


Parameter Details

  • NA

Return Value

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


The following below is a simple example -

import time

def procedure():

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

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

Below is the output of the above example -

0.014447 seconds process time
2.50159311295 seconds wall time

Alright guys! This is where we are rounding up for this tutorial guide. In my next tutorial, we are going to be studying about Python Time ctime() method.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.


Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.