GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — time.monotonic() should use a different clock source on Windows · Issue #88494 · python/cpython

time.monotonic() should use a different clock source on Windows #88494

New issue
Copy link
New issue
Copy link
Closed
Closed
time.monotonic() should use a different clock source on Windows#88494
Copy link
Labels
3.12only security fixesonly security fixesOS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

lunixbochs
mannequin
opened on Jun 6, 2021
Issue body actions
BPO 44328
Nosy @pfmoore, @abalkin, @vstinner, @tjguk, @zware, @eryksun, @zooba, @pganssle, @lunixbochs

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 = None
created_at = <Date 2021-06-06.22:05:07.766>
labels = ['3.11', 'library', 'OS-windows', 'performance']
title = 'time.monotonic() should use a different clock source on Windows'
updated_at = <Date 2021-06-14.21:10:46.833>
user = 'https://github.com/lunixbochs'

bugs.python.org fields:

activity = <Date 2021-06-14.21:10:46.833>
actor = 'eryksun'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)', 'Windows']
creation = <Date 2021-06-06.22:05:07.766>
creator = 'lunixbochs2'
dependencies = []
files = []
hgrepos = []
issue_num = 44328
keywords = []
message_count = 12.0
messages = ['395221', '395238', '395490', '395493', '395681', '395683', '395719', '395769', '395771', '395782', '395784', '395849']
nosy_count = 9.0
nosy_names = ['paul.moore', 'belopolsky', 'vstinner', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'p-ganssle', 'lunixbochs2']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue44328'
versions = ['Python 3.11']

Linked PRs

  • gh-88494: Use QueryPerformanceCounter() for time.monotonic() #116781
  • gh-88494: Reduce CLOCK_RES to 1 ms in tests #118395

Activity

Next
  1. lunixbochs commented on Jun 6, 2021

    @lunixbochs
    lunixbochsmannequin
    on Jun 6, 2021
    MannequinAuthor
    More actions

    Related to https://bugs.python.org/issue41299#msg395220

    Presumably time.monotonic() on Windows historically used GetTickCount64() because QueryPerformanceCounter() could fail. However, that hasn't been the case since Windows XP: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter

    On systems that run Windows XP or later, the function will always succeed and will thus never return zero

    I've run into issues with this when porting python-based applications to Windows. On other platforms, time.monotonic() was a decent precision so I used it. When I ported to Windows, I had to replace all of my time.monotonic() calls with time.perf_counter(). I would pretty much never knowingly call time.monotonic() if I knew ahead of time it could be quantized to 16ms.

    My opinion is that the GetTickCount64() monotonic time code in CPython should be removed entirely and only the QueryPerformanceCounter() path should be used.

    I also think some of the failure checks could be removed from QueryPerformanceCounter() / QueryPerformanceFrequency(), as they're documented to never fail in modern Windows and CPython has been dropping support for older versions of Windows, but that's less of a firm opinion.

  2. lunixbochs
    added
    3.8 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    3.10 (EOL)end of lifeend of life
    3.11only security fixesonly security fixes
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    OS-windows
    performancePerformance or resource usagePerformance or resource usage
    on Jun 6, 2021
  3. 28 remaining items

  4. vstinner
    added 2 commits that reference this issue on Mar 14, 2024

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic()

    2b670fc

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic()

    84632e9
  5. vstinner commented on Mar 14, 2024

    @vstinner
    vstinner
    on Mar 14, 2024
    Member
    More actions

    I created #116781 to use QueryPerformanceCounter() for time.monotonic().

  6. vstinner commented on Mar 14, 2024

    @vstinner
    vstinner
    on Mar 14, 2024
    Member
    More actions

    See also issue gh-115637.

  7. vstinner
    added 4 commits that reference this issue on Mar 14, 2024

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic()

    28d2357

    gh-88494: Use QueryPerformanceCounter() for time.monotonic() (#116781)

    846ad5a

    pythongh-88494: Use GetSystemTimePreciseAsFileTime() in time.time()

    f6eec65

    pythongh-88494: Use GetSystemTimePreciseAsFileTime() in time.time()

    4ef53f4
  8. vstinner commented on Mar 15, 2024

    @vstinner
    vstinner
    on Mar 15, 2024
    Member
    More actions

    time.monotonic() now uses QueryPerformanceCounter() (commit) and has a resolution lower than 1 us. I measured 100 ns (10 MHz) on my Windows 11 VM, whereas before it was 15.6 ms (64 Hz): the updated clock resolution is 156,000x better :-)

    Thanks everybody for looking into this issue and providing very useful technical details about these clocks.

    Follow-up: see issue gh-63207 to use GetSystemTimePreciseAsFileTime() for time.time().

  9. vstinner
    closed this as completedon Mar 15, 2024
  10. github-project-automation
    moved this to Done in Date and time issues 🕰️on Mar 15, 2024
  11. vstinner
    added a commit that references this issue on Mar 20, 2024

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic() (p…

    ae432c8
  12. adorilson
    added a commit that references this issue on Mar 25, 2024

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic() (p…

    64bd681
  13. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-88494: Use QueryPerformanceCounter() for time.monotonic() (p…

    1169a0a
  14. vstinner
    added a commit that references this issue on Apr 29, 2024

    pythongh-88494: Reduce CLOCK_RES to 1 ms in tests

    be949bb
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

    3.12only security fixesonly security fixesOS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

    Projects

    • Date and time issues 🕰️
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.