bpo-45429: Support CREATE_WAITABLE_TIMER_HIGH_RESOLUTION if possible#29203
Conversation
Co-authored-by: Eryk Sun <eryksun@gmail.com>
aa8d2ef to
eabd853
Compare
|
@vstinner gentle ping |
| #endif | ||
|
|
||
| #if defined(MS_WINDOWS) | ||
| if ((LONG)timer_flags == -1) { |
There was a problem hiding this comment.
| if ((LONG)timer_flags == -1) { | |
| if (timer_flags == (DWORD)-1) { |
| #define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002 | ||
| #endif | ||
|
|
||
| static DWORD timer_flags = -1; |
There was a problem hiding this comment.
| static DWORD timer_flags = -1; | |
| static DWORD timer_flags = (DWORD)-1; |
| @@ -0,0 +1,3 @@ | |||
| On Windows, :func:`time.sleep` now uses a waitable timer which supports | |||
| high-resolution timers without increasing the timer frequency if possible. | |||
There was a problem hiding this comment.
I suggest to omit "without increasing the timer frequency if possible":
| high-resolution timers without increasing the timer frequency if possible. | |
| high-resolution timers. |
(same change where you copied this doc)
There was a problem hiding this comment.
Maybe you can explain that in Python 3.10, the best resolution was 1 ms, whereas it's now better (smaller) than 1 ms.
|
The change works as expected on my Windows 10 "version 21H1" VM ("OS Build 19043.1348"). On a debug build (worse performance than a release build), bench.py of https://bugs.python.org/issue21302 says: With this PR, I get: It's ~1000x more accurate: ms (10^-3 sec) => us (10^-6 sec)! |
| (Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.) | ||
|
|
||
| * On Windows, :func:`time.sleep` now uses a waitable timer which supports high-resolution timers. | ||
| In Python 3.10, the best resolution was 1 ms, from Python 3.11 it's now smaller than 1 ms. |
There was a problem hiding this comment.
Maybe try to merge this this item with the previous one.
vstinner
left a comment
There was a problem hiding this comment.
LGTM. The code is correct, there is maybe a way to enhance the What's New In Python 3.11 doc.
Will do it at separated PR (maybe tomorrow) |
https://bugs.python.org/issue45429