Skip to content

Deprecate time.clock() #58517

Closed
Closed

Description

@vstinner
BPO 14309
Nosy @malemburg, @pitrou, @vstinner, @giampaolo

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:

assignee = None
closed_at = <Date 2012-04-29.00:53:40.332>
created_at = <Date 2012-03-15.00:52:01.905>
labels = ['library']
title = 'Deprecate time.clock()'
updated_at = <Date 2012-04-29.00:54:22.864>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2012-04-29.00:54:22.864>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2012-04-29.00:53:40.332>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2012-03-15.00:52:01.905>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 14309
keywords = []
message_count = 10.0
messages = ['155831', '155866', '155873', '156063', '156335', '156341', '157519', '157520', '159555', '159556']
nosy_count = 5.0
nosy_names = ['lemburg', 'pitrou', 'vstinner', 'giampaolo.rodola', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue14309'
versions = ['Python 3.3']

Activity

  1. vstinner commented on Mar 15, 2012

    @vstinner
    MemberAuthor

    Python 3.3 has 3 functions to get time:

    • time.clock()
    • time.steady()
    • time.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)

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 15, 2012
  3. malemburg commented on Mar 15, 2012

    @malemburg
    Member

    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 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.

  4. vstinner commented on Mar 15, 2012

    @vstinner
    MemberAuthor

    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.

  5. malemburg commented on Mar 16, 2012

    @malemburg
    Member

    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.

  6. vstinner commented on Mar 19, 2012

    @vstinner
    MemberAuthor

    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?

  7. malemburg commented on Mar 19, 2012

    @malemburg
    Member

    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 ?

  8. vstinner commented on Apr 4, 2012

    @vstinner
    MemberAuthor

    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).

  9. vstinner commented on Apr 4, 2012

    @vstinner
    MemberAuthor

    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.

  10. python-dev commented on Apr 29, 2012

    python-devmannequin
    Mannequin

    New changeset 314c3faea2fb by Victor Stinner in branch 'default':
    Close bpo-14309: Deprecate time.clock()
    http://hg.python.org/cpython/rev/314c3faea2fb

  11. vstinner commented on Apr 29, 2012

    @vstinner
    MemberAuthor

    The PEP-418 has been accepted: read it to understand why time.clock() is now deprecated.

  12. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions