[issue31803] time.clock() should emit a DeprecationWarning

Marc-Andre Lemburg report at bugs.python.org
Wed Oct 25 12:09:05 EDT 2017


Marc-Andre Lemburg <mal at egenix.com> added the comment:

On 25.10.2017 01:31, STINNER Victor wrote:
> 
> Marc-Andre: "Yes, to avoid yet another Python 2/3 difference. It should be replaced with the appropriate variant on Windows and non-Windows platforms. From Serhiy's response that's time.process_time() on non-Windows platforms and time.perf_counter() on Windows."
> 
> I don't understand why you mean by "replaced with". Do you mean modify the implementation of the time.clock()?

What I meant is that time.clock() is replaced with the higher
accuracy timers corresponding to the current time.clock()
implementation on the various platforms in order to retain
backwards compatibility.

In other words:

if sys.platform == 'win32':
    time.clock = time.perf_counter
else:
    time.clock = time.process_time

I know that time.clock() behaves differently on different platforms,
but this fact has been known for a long time and is being used by
Python code out there for timing purposes.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31803>
_______________________________________


More information about the Python-bugs-list mailing list