-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
clarify that time_ns is monotonic #57129
base: master
Are you sure you want to change the base?
Conversation
For reference, I also want link the discussion at w3c/hr-time#115 — it turns out that whether |
This should be backported to older versions, at least latest 1.10.x, not just its next minor version?! Specifically, and also pointing out, and asking about general doc policy, when it's not a new feature, but applied to the existing one, like here. |
be monotonic (mod 2⁶⁴) while the system is running, and is unaffected by clock drift or changes to local calendar time, | ||
but it may change arbitrarily across system reboots or suspensions. | ||
|
||
(Although the returned time is always in nanoseconds, the timing resolution is platform-dependent.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in its own paragraph with parenthesis? Seems like it is just as relevant as the other text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I thought it was kind of obvious that units ≠ resolution (i.e. precision ≠ accuracy), so this paragraph is just a gentle reminder / clarification (since the preceding paragraph already says that the units are ns)? But if you want to remove the parens that's fine with me.
Co-authored-by: Kristoffer Carlsson <[email protected]>
Since
time_ns()
is based onuv_hrtime
, the docs should note that it is guaranteed to be monotonic (see also #2464 and this discourse thread). This PR also notes that you can't compare times across machines or reboots, and that the timing resolution is system-dependent.On Unix systems, it calls
clock_gettime(CLOCK_MONOTONIC, &t)
and the GNU libc manual notes that the reference time "may change if the system is rebooted or suspended." On Windows, it callsQueryPerformanceCounter
.(This docstring was last discussed in #54696.)
Also, I changed
To "The primary use is for measuring elapsed times during program execution" (emphasis added), since you don't want to use this to compare arbitrary "moments", e.g. from different runs of a program (that may span a system reboot).