We now have a youtube channel. Subscribe!

Python Time clock() Method with example



Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we are going to be studying about the Python Time clock() method.

The Python Time clock() function returns the current processor time as a floating point number that's 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, this function returns wall-clock seconds elapsed since the first call of this method, as a floating point number, based on the Microsoft Windows32 method QueryPerformaceCounter.

Syntax

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

time.clock()


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.

Example

The following below is a simple example -

#!/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"

Output
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 our next tutorial, we are going to be studying about the 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.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain