-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
time.perf_counter() should state more clearly (or deny) that it is monotonic #115637
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@vstinner, I think you might be the expert here? :) |
alright, i guess #115638 should fix the docs then. :) |
From my personal opinion, the fact that it is currently monotonic, does not mean that we should document it and make a promise about it. We already promised one thing about |
I'm not 100% sure that perf_counter() is always monotonic in all cases on all platforms. It would help to have some evidence on Linux, Windows, macOS. |
See also #88494 On Windows, QueryPerformanceCounter() is implemented by reading x86 TSC. Ten years ago, TSC causes issues when the CPU frequency changed: recent CPU now have a TSC which is no longer related to the CPU frequency. There were also a few issues related to virtualization. Today, Windows documentation just says: https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps
where QPC stands for QueryPerformanceCounter(). Linux supports multiple clock sources and can switch to the next one at runtime if Linux decides that a clock is not reliable. Example on my laptop:
TSC and ACPI PM are available and TSC is the current clock source. |
Oh, in fact, Python
|
from what i can tell in the Fine Source Code: Lines 1327 to 1335 in aa8c1a0
it does look like on everything but But those are implementation details: i think the fundamental question here is whether or not the plan was to have the performance counter be monotonic in the first place, or, if that's the requirement anyway. Looking at it from a library consumer perspective, i'm looking at the codetiming package and it's implemented with perf_counter. it's exactly the kind of module I would expect perf_counter to be used for, but I would also be extremely surprised if the counter would go backwards on time shifts, for example. So I would personnally argue that |
Documentation
I was trying to figure out the distinction between
perf_counter
andmonotonic
, and it's not entirely clear to me, even after reading PEP 418. I think it is monotonic, but I'm not sure.So I'm invoking the Python gods here: what's the actual wanted behavior here? And why isn't it more clearly stated in the docs?
Thanks!
Linked PRs
The text was updated successfully, but these errors were encountered: