[New-bugs-announce] [issue31803] Remove not portable time.clock(), replaced by time.perf_counter() and time.process_time()
STINNER Victor
report at bugs.python.org
Tue Oct 17 09:00:45 EDT 2017
New submission from STINNER Victor <victor.stinner at gmail.com>:
The behaviour of the time.clock() function is not portable: on Windows it mesures wall-clock, whereas it measures CPU time on Unix. Python has time.process_time() and time.perf_counter(), since Python 3.3, which are portable, well defined and have a better resolution.
time.clock() was deprecated in Python 3.3 documentation, but calling time.clock() didn't raise a DeprecationWarning. I proposed to remove it from Python 3.7.
Sometimes, a deprecated function raises a DeprecationWarning in Python version N, before removing it from Python version N. time.clock() doesn't emit such warning, but I consider that it is possible to remove it anyway.
While it can be annoying to have to patch code to no more use time.clock(), I consider that it's worth it for portability and better clock resolution.
Attached PR removes time.clock() and time.get_clock_info() doens't accept 'clock' anymore.
Current time.clock() documentation:
----------------------------
.. function:: clock()
.. index::
single: CPU time
single: processor time
single: benchmarking
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.
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
:c:func:`QueryPerformanceCounter`. The resolution is typically better than one
microsecond.
.. deprecated:: 3.3
The behaviour of this function depends on the platform: use
:func:`perf_counter` or :func:`process_time` instead, depending on your
requirements, to have a well defined behaviour.
----------------------------
----------
components: Library (Lib)
messages: 304502
nosy: haypo
priority: normal
severity: normal
status: open
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31803>
_______________________________________
More information about the New-bugs-announce
mailing list