New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate time.clock() #58517
Comments
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 (time.wallclock was the old name of time.steady) |
STINNER Victor wrote:
Strong -1 on this idea. time.clock() has been in use for ages in many many scripts. We don't |
I don't want to remove the function, just mark it as deprecated to |
STINNER Victor wrote:
Why ? There's no other single function providing the same functionality, Similar functionality is available via several different functions, |
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? |
STINNER Victor wrote:
time.clock() does exactly what the docs say: you get access to
What for ? time.clock() uses the same timer as time.steady() on Windows,
And what's the advantage of that over using time.clock() directly ? |
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). |
Lib/profile.py tests also various functions to choose the best one in Profile constructor. |
New changeset 314c3faea2fb by Victor Stinner in branch 'default': |
The PEP-418 has been accepted: read it to understand why time.clock() is now deprecated. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: