Issue 14309: Deprecate time.clock() - Python tracker (original) (raw)

Created on 2012-03-15 00:52 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (10)
msg155831 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-15 00:52
Python 3.3 has 3 functions to get time: - time.clock() - time.steady() - time.time() Antoine Pitrou suggested to deprecated time.clock() in (issue #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)
msg155866 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2012-03-15 06:37
STINNER Victor wrote: > > New submission from STINNER Victor <victor.stinner@gmail.com>: > > Python 3.3 has 3 functions to get time: > > - time.clock() > - time.steady() > - time.time() > > Antoine Pitrou suggested to deprecated time.clock() in (issue #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.
msg155873 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-15 09:31
> time.clock() has been in use for ages in many many scripts. > We don't want to carelessly break all those. 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.
msg156063 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2012-03-16 18:05
STINNER Victor wrote: > > STINNER Victor <victor.stinner@gmail.com> added the comment: > >> time.clock() has been in use for ages in many many scripts. >> We don't want to carelessly break all those. > > 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. 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.
msg156335 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-19 12:46
> 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?
msg156341 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2012-03-19 14:14
STINNER Victor wrote: > > STINNER Victor <victor.stinner@gmail.com> added the comment: > >> 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() 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. > On Windows, time.clock() should be replaced by time.steady(). What for ? time.clock() uses the same timer as time.steady() on Windows, AFAICT, so all you change is the name of the function. > On UNIX, time.clock() can be replaced with "usage=os.times(); usage[0]+usage[1]" for example. And what's the advantage of that over using time.clock() directly ?
msg157519 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-04 23:43
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).
msg157520 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-04 23:49
> Something can be done to provide portable functions to get > the user and system times. Lib/profile.py tests also various functions to choose the best one in Profile constructor.
msg159555 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-29 00:53
New changeset 314c3faea2fb by Victor Stinner in branch 'default': Close #14309: Deprecate time.clock() http://hg.python.org/cpython/rev/314c3faea2fb
msg159556 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-29 00:54
The PEP 418 has been accepted: read it to understand why time.clock() is now deprecated.
History
Date User Action Args
2022-04-11 14:57:28 admin set github: 58517
2012-04-29 00:54:22 vstinner set messages: +
2012-04-29 00:53:40 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2012-04-04 23:49:30 vstinner set messages: +
2012-04-04 23:43:50 vstinner set messages: +
2012-03-19 14:14:16 lemburg set messages: +
2012-03-19 12:46:56 vstinner set messages: +
2012-03-16 18:05:31 lemburg set messages: +
2012-03-15 09:36:23 giampaolo.rodola set nosy: + giampaolo.rodola
2012-03-15 09:31:29 vstinner set messages: +
2012-03-15 06:37:48 lemburg set nosy: + lemburgmessages: +
2012-03-15 00:52:01 vstinner create