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

STINNER Victor report at bugs.python.org
Wed Oct 18 05:15:42 EDT 2017


STINNER Victor <victor.stinner at gmail.com> added the comment:

"Initially the time module was a thin wrapper around C and OS time-related functions. It may be confusing that the behavior of time.clock() differs from the behavior of C's clock()."

Well, there is the theory, and there is the practice. Someone decided to implement time.clock() with QueryPerformanceCounter() on Windows, and so time.clock() is no more a thin wrapper to the C clock() function since at least Python 2.7 (I didn't check earlier versions).

Portability on clocks is even more than complex than in the os module, especially when you want the same behaviour on Windows and Unix. The PEP 418 added new clocks with a better defined behaviour to "fix" this issue.


"The documentation for clock() on MSDN suggests to use GetProcessTimes() for the behavior conforming the C standard."

time.process_time() is implemented with GetProcessTimes(). That's why time.clock() suggests to either replace it with time.perf_counter() or time.process_time().

----------

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


More information about the Python-bugs-list mailing list