Skip to content

time.clock () has very low resolution on Linux #57470

Closed

Description

@ellioh
mannequin
BPO 13261
Nosy @vstinner
Files
  • monotime_unix.py: A workaround using clock_gettime from librt
  • 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 2011-10-25.09:39:26.816>
    created_at = <Date 2011-10-25.09:37:06.950>
    labels = ['type-bug']
    title = 'time.clock () has very low resolution on Linux'
    updated_at = <Date 2011-10-25.09:39:26.814>
    user = 'https://bugs.python.org/ellioh'

    bugs.python.org fields:

    activity = <Date 2011-10-25.09:39:26.814>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-10-25.09:39:26.816>
    closer = 'vstinner'
    components = ['None']
    creation = <Date 2011-10-25.09:37:06.950>
    creator = 'ellioh'
    dependencies = []
    files = ['23515']
    hgrepos = []
    issue_num = 13261
    keywords = []
    message_count = 2.0
    messages = ['146347', '146348']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'ellioh']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13261'
    versions = ['Python 2.6', 'Python 2.7']

    Activity

    1. ellioh commented on Oct 25, 2011

      elliohmannequin
      MannequinAuthor

      time.clock () has very poor time resolution on Linux (tested on Ubuntu 11.04).

      The result of call to clock () changes once per several seconds. On the other side, on Windows it provides very good resolution.

      Here is a doctest that fails on Linux:
      """
       >>> from time import sleep
       >>> prev = clock ()
       >>> res = True
       >>> for i in xrange(10):
       ...     sleep(0.15)
       ...     next = clock ()
       ...     res = res and (next - prev) > 0.1
       ...     prev = next
       >>> print res
       True
      """

      Currently on Linux I am using a workaround that is attached to the issue.

    2. added
      type-bugAn unexpected behavior, bug, or error
      on Oct 25, 2011
    3. vstinner commented on Oct 25, 2011

      @vstinner
      Member

      This issue is a duplicate of the issue bpo-10278.

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

      type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions