Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-63207: Use GetSystemTimePreciseAsFileTime() in time.time()#116822

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:time_precise
Mar 18, 2024

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedMar 14, 2024
edited
Loading

@vstinnervstinner changed the titlegh-88494: Use GetSystemTimePreciseAsFileTime() in time.time()gh-63207: Use GetSystemTimePreciseAsFileTime() in time.time()Mar 14, 2024
@vstinner
Copy link
MemberAuthor

cc@pitrou@eryksun@zooba

@vstinner
Copy link
MemberAuthor

Clock resolution measured by the script:#116781 (comment)

Before:

time():- efffective resolution: 15 ms- implementation: GetSystemTimeAsFileTime()- resolution: 16 msperf_counter():- efffective resolution: 100 ns- implementation: QueryPerformanceCounter()- resolution: 100 nsmonotonic():- efffective resolution: 100 ns- implementation: QueryPerformanceCounter()- resolution: 100 ns

After:

time():- efffective resolution: 238 ns- implementation: GetSystemTimePreciseAsFileTime()- resolution: 100 nsperf_counter():- efffective resolution: 100 ns- implementation: QueryPerformanceCounter()- resolution: 100 nsmonotonic():- efffective resolution: 100 ns- implementation: QueryPerformanceCounter()- resolution: 100 ns

time.time() resolution is way better! 238 ns instead of 15.6 ms, it's around 65 500x more accurate!

@vstinner
Copy link
MemberAuthor

On a release build (build usingPCbuild\build.bat -e -p x64 command), I confirm thatGetSystemTimePreciseAsFileTime() ("change") is slower thanGetSystemTimeAsFileTime() ("ref"):

vstinner@WIN C:\victor\python\main>env\Scripts\python -m pyperf compare_to ref.json change.json                                           Mean +- std dev: [ref] 35.8 ns +- 0.8 ns -> [change] 52.9 ns +- 2.2 ns: 1.48x slower

Well, more and more operating have two clocks: one slow but accurate, and one fast but less accurate. Example on Linux:

  • CLOCK_REALTIME
  • CLOCK_REALTIME_COARSE: A faster but less precise version of CLOCK_REALTIME

Python uses CLOCK_REALTIME for time.time(), the most precise one. So it's consistent to use the most accurate clock for time.time() on Windows as well.

If tomorrow, performance becomes an issue, we can add a newtime.time_coarse() function which would use CLOCK_REALTIME_COARSE on Linux, and GetSystemTimeAsFileTime() on Windows.

@pitrou
Copy link
Member

time.time() resolution is way better! 238 ns instead of 15.6 ms, it's around 65 500x more accurate!

Impressive! Finally Windows will be as good as other platforms here.

vstinner and eryksun reacted with hooray emoji

@@ -55,6 +55,14 @@
#endif


#ifdef MS_WINDOWS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, I think checking forMS_WINDOWS here is sufficient.GetSystemTimePreciseAsFileTime(),QueryPerformanceCounter(), andQueryPerformanceFrequency() are available in the system, app, and game partitions. The old use ofGetSystemTimeAdjustment() actually wasn't supported for app builds. However, that function was used improperly anyway.

@vstinnervstinner merged commit1d95451 intopython:mainMar 18, 2024
@vstinnervstinner deleted the time_precise branchMarch 18, 2024 16:13
vstinner added a commit to vstinner/distributed that referenced this pull requestMay 7, 2024
Closesdask#8641._WindowsTime is no longer needed on Windows with Python 3.13. OnWindows, Python 3.13 now uses GetSystemTimePreciseAsFileTime() fortime.time() and QueryPerformanceCounter() for time.monotonic().*python/cpython#116781*python/cpython#116822
fjetter pushed a commit to dask/distributed that referenced this pull requestMay 8, 2024
Closes#8641._WindowsTime is no longer needed on Windows with Python 3.13. OnWindows, Python 3.13 now uses GetSystemTimePreciseAsFileTime() fortime.time() and QueryPerformanceCounter() for time.monotonic().*python/cpython#116781*python/cpython#116822
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 30, 2025
pythonGH-136068)(cherry picked from commit486587d)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 30, 2025
pythonGH-136068)(cherry picked from commit486587d)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
vstinner pushed a commit that referenced this pull requestJun 30, 2025
…-136068) (#136138)gh-63207: Update `time.time` documentation afterGH-116822 (GH-136068)(cherry picked from commit486587d)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
vstinner pushed a commit that referenced this pull requestJun 30, 2025
…-136068) (#136139)gh-63207: Update `time.time` documentation afterGH-116822 (GH-136068)(cherry picked from commit486587d)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull requestJul 11, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull requestJul 12, 2025
picnixz pushed a commit to picnixz/cpython that referenced this pull requestJul 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@eryksuneryksuneryksun approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@vstinner@pitrou@eryksun

[8]ページ先頭

©2009-2025 Movatter.jp