You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Antoine Pitrou suggested to deprecated time.clock() in msg120149 (issue bpo-10278).
"The problem is time.clock(), since it does two wildly different things
depending on the OS. I would suggest to deprecate time.clock() at the same time as we add time.wallclock(). For the Unix-specific definition of time.clock(), there is already os.times() (which gives even richer information)."
Antoine Pitrou suggested to deprecated time.clock() in msg120149 (issue bpo-10278).
"The problem is time.clock(), since it does two wildly different things
depending on the OS. I would suggest to deprecate time.clock() at the same time as we add time.wallclock(). For the Unix-specific definition of time.clock(), there is already os.times() (which gives even richer information)."
(time.wallclock was the old name of time.steady)
Strong -1 on this idea.
time.clock() has been in use for ages in many many scripts. We don't
want to carelessly break all those.
There's no other single function providing the same functionality
time.clock() is not portable: it is a different clock depending on the OS. To write portable code, you have to use the right function:
time.time()
time.steady()
os.times(), resource.getrusage()
On Windows, time.clock() should be replaced by time.steady(). On UNIX, time.clock() can be replaced with "usage=os.times(); usage[0]+usage[1]" for example.
Which kind of use case is not covered by these functions?
I misunderstood the time.clock() function. It counts the CPU time while the process is active, whereas a monotonic clock counts elapsed time even during a sleep. time.clock() and time.monotonic() are different clocks for different purposes.
I wrote the PEP-418 which contains a list of all available OS clocks. It lists monotonic clocks, but also "process time" and "thread time" clocks. And it has a "Deferred API: time.perf_counter()" section.
Something can be done to provide portable functions to get the user and system times. See for example Tools/pybench/systimes.py written by Marc-Andre Lemburg.
Python 3.3 gives access to clock_gettime(CLOCK_PROCESS_CPUTIME_ID) and clock_gettime(CLOCK_THREAD_CPUTIME_ID).
Activity
vstinner commentedon Mar 15, 2012
Python 3.3 has 3 functions to get time:
Antoine Pitrou suggested to deprecated time.clock() in msg120149 (issue bpo-10278).
"The problem is time.clock(), since it does two wildly different things
depending on the OS. I would suggest to deprecate time.clock() at the same time as we add time.wallclock(). For the Unix-specific definition of time.clock(), there is already os.times() (which gives even richer information)."
(time.wallclock was the old name of time.steady)
malemburg commentedon Mar 15, 2012
STINNER Victor wrote:
Strong -1 on this idea.
time.clock() has been in use for ages in many many scripts. We don't
want to carelessly break all those.
vstinner commentedon Mar 15, 2012
I don't want to remove the function, just mark it as deprecated to
avoid confusion. It will only be removed from the next major Python.
malemburg commentedon Mar 16, 2012
STINNER Victor wrote:
Why ? There's no other single function providing the same functionality,
so it's not even a candidate for deprecation.
Similar functionality is available via several different functions,
but that's true for a lot functions in th stdlib.
vstinner commentedon Mar 19, 2012
time.clock() is not portable: it is a different clock depending on the OS. To write portable code, you have to use the right function:
On Windows, time.clock() should be replaced by time.steady(). On UNIX, time.clock() can be replaced with "usage=os.times(); usage[0]+usage[1]" for example.
Which kind of use case is not covered by these functions?
malemburg commentedon Mar 19, 2012
STINNER Victor wrote:
time.clock() does exactly what the docs say: you get access to
a CPU timer. It's normal that CPU timers work differently on
different OSes.
What for ? time.clock() uses the same timer as time.steady() on Windows,
AFAICT, so all you change is the name of the function.
And what's the advantage of that over using time.clock() directly ?
vstinner commentedon Apr 4, 2012
I misunderstood the time.clock() function. It counts the CPU time while the process is active, whereas a monotonic clock counts elapsed time even during a sleep. time.clock() and time.monotonic() are different clocks for different purposes.
I wrote the PEP-418 which contains a list of all available OS clocks. It lists monotonic clocks, but also "process time" and "thread time" clocks. And it has a "Deferred API: time.perf_counter()" section.
Something can be done to provide portable functions to get the user and system times. See for example Tools/pybench/systimes.py written by Marc-Andre Lemburg.
Python 3.3 gives access to clock_gettime(CLOCK_PROCESS_CPUTIME_ID) and clock_gettime(CLOCK_THREAD_CPUTIME_ID).
vstinner commentedon Apr 4, 2012
Lib/profile.py tests also various functions to choose the best one in Profile constructor.
python-dev commentedon Apr 29, 2012
New changeset 314c3faea2fb by Victor Stinner in branch 'default':
Close bpo-14309: Deprecate time.clock()
http://hg.python.org/cpython/rev/314c3faea2fb
vstinner commentedon Apr 29, 2012
The PEP-418 has been accepted: read it to understand why time.clock() is now deprecated.