As of 3.3, time.clock() is deprecated, and it's suggested to use time.process_time() or time.perf_counter() instead.

Previously in 2.7, according to the time module docs:

time.clock()

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the 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 to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.

Additionally, there is the timeit module for benchmarking code snippets.

Answer from Jason Navarrete on Stack Overflow
🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions — Python 3.14.4 documentation
Added in version 3.3. ... Similar to clock_gettime() but return time as nanoseconds.
🌐
Tutorialspoint
tutorialspoint.com › python › time_clock.htm
Python 3 - time clock() Method
The Python time clock() method is used to get the current processor time. It is returned as a floating point number expressed in seconds. If the amount of time required to execute a program is to be calculated, the method needs to be invoked ...
🌐
Python Module of the Week
pymotw.com › 3 › time
time — Clock Time — PyMOTW 3
December 9, 2018 - $ python3 time_ctime.py The time is : Sun Dec 9 12:43:43 2018 15 secs from now : Sun Dec 9 12:43:58 2018 · Because time() looks at the system clock, and the system clock can be changed by the user or system services for synchronizing clocks across multiple computers, calling time() repeatedly may produce values that go forwards and backwards.
🌐
GeeksforGeeks
geeksforgeeks.org › python-time-clock-method
Python | time.clock() method - GeeksforGeeks
December 8, 2022 - As, Most of the functions defined in time module call corresponding C library function. time.clock() method also call C library function of the same name to get the result. The precision of returned float value depends on the called C library function. Note: This method is deprecated since Python version 3.3 and will be removed in Python version 3.8.
🌐
GitHub
github.com › wxWidgets › Phoenix › issues › 1510
time.clock() removed in Python3.8 replace with time.perf_counter() · Issue #1510 · wxWidgets/Phoenix
February 9, 2020 - The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior.
Author   Metallicow
🌐
GitHub
github.com › vispy › vispy › issues › 1659
Time.clock was deprecated in python 3.3, and was removed in python 3. 8 · Issue #1659 · vispy/vispy
July 9, 2019 - From the python 3.8 changelog:https://docs.python.org/3/whatsnew/3.8.html The function time.clock() has been removed, it was deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requireme...
Author   ritobanrc
Find elsewhere
🌐
Python
docs.python.org › 3.3 › library › time.html
16.3. time — Time access and conversions — Python 3.3.7 documentation
The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the 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 to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond. Deprecated since version 3.3: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.
🌐
Javatpoint
javatpoint.com › time-clock-method-in-python
Time clock() Method in Python - Javatpoint
Time clock() Method in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
Python Central
pythoncentral.io › measure-time-in-python-time-time-vs-time-clock
Measure Time in Python - time.time() vs time.clock() - Python Central
December 29, 2021 - Instead of dealing with the different behaviors of time.time() and time.clock() on different platforms, which is often error-prone, Python's timeit module provides a simple way for timing. Besides calling it directly from code, you can also call it from the command-line. ... [shell] % python -m timeit -n 10000 '[v for v in range(10000)]' 10000 loops, best of 3: 365 usec per loop % python -m timeit -n 10000 'map(lambda x: x^2, range(1000))' 10000 loops, best of 3: 145 usec per loop [/shell]
🌐
Python
bugs.python.org › issue31803
Issue 31803: time.clock() should emit a DeprecationWarning - Python tracker
October 17, 2017 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/75984
🌐
Python Forum
python-forum.io › thread-33203.html
time.clock not functioning
I am using the following coding, from a text book, to compare two methods of measuring execution time for coding but time.clock is not recognised. I am on Windows 10 using Python 3.9.2 The coding is: import time def do_my_sum(xs): sum = 0 ...
🌐
Python Module of the Week
pymotw.com › 2 › time
time – Functions for manipulating clock time - Python Module of the Week
March 9, 2008 - Now available for Python 3! Buy the book! ... The time module exposes C library functions for manipulating dates and times. Since it is tied to the underlying C implementation, some details (such as the start of the epoch and maximum date value supported) are platform-specific.
🌐
Programiz
programiz.com › python-programming › time
Python time Module (with Examples)
The time.ctime() function in Python takes seconds passed since epoch as an argument and returns a string representing local time.
🌐
Python
docs.python.org › 3.0 › library › time.html
time — Time access and conversions — Python v3.0.1 documentation
The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the 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 to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter.
🌐
GitHub
gist.github.com › YannBouyeron › 1083709633f78e6804602a7ac6ae4bfa
Utiliser le module Time de Python.md · GitHub
import time t0 = time.clock() x = 0 while x < 10000: x = x + 1 tf = time.clock() dt = tf-t0 ... >>> import time >>> l = time.localtime() >>> g = time.gmtime() >>> l time.struct_time(tm_year=2016, tm_mon=3, tm_mday=21, tm_hour=18, tm_min=16, tm_sec=50, tm_wday=0, tm_yday=81, tm_isdst=0) >>> g time.struct_time(tm_year=2016, tm_mon=3, tm_mday=21, tm_hour=18, tm_min=17, tm_sec=0, tm_wday=0, tm_yday=81, tm_isdst=0) >>> time.mktime(l) 1458584210.0 >>> time.mktime(g) 1458584220.0
🌐
Real Python
realpython.com › python-timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
December 8, 2024 - For more background on classes and object-oriented programming, check out Python Classes: The Power of Object-Oriented Programming, Object-Oriented Programming (OOP) in Python or the official documentation. Classes are good for tracking state. In a Timer class, you want to keep track of when a timer starts and how much time has passed since then. For the first implementation of Timer, you’ll add a ._start_time attribute, as well as .start() and .stop() methods. Add the following code to a file named timer.py: ... 1import time 2 3class TimerError(Exception): 4 """A custom exception used to report errors in use of Timer class""" 5 6class Timer: 7 def __init__(self): 8 self._start_time = None 9 10 def start(self): 11 """Start a new timer""" 12 if self._start_time is not None: 13 raise TimerError(f"Timer is running.
🌐
Python
bugs.python.org › issue14309
Issue 14309: Deprecate time.clock() - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/58517