Skip to content

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Jan 22, 2025

Since time_ns() is based on uv_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 calls QueryPerformanceCounter.

(This docstring was last discussed in #54696.)

Also, I changed

The primary use is for measuring the elapsed time between two moments in time.

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).

@stevengj stevengj added docs This change adds or pertains to documentation dates Dates, times, and the Dates stdlib module labels Jan 22, 2025
@stevengj
Copy link
Member Author

For reference, I also want link the discussion at w3c/hr-time#115 — it turns out that whether CLOCK_MONOTONIC ticks during sleep is system-dependent.

@PallHaraldsson
Copy link
Contributor

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.

@IanButterworth IanButterworth added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 labels Jan 23, 2025
This was referenced Jan 28, 2025
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.)
Copy link
Member

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.

Copy link
Member Author

@stevengj stevengj Jan 30, 2025

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 <kcarlsson89@gmail.com>
This was referenced Mar 11, 2025
@KristofferC KristofferC mentioned this pull request Apr 25, 2025
71 tasks
@inkydragon
Copy link
Member

Assuming this is ready to be merged.

@inkydragon inkydragon added the merge me PR is reviewed. Merge when all tests are passing label Apr 29, 2025
@KristofferC KristofferC merged commit b9a0497 into master Apr 29, 2025
6 of 8 checks passed
@KristofferC KristofferC deleted the stevengj-patch-4 branch April 29, 2025 15:34
@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Apr 29, 2025
@inkydragon inkydragon removed the merge me PR is reviewed. Merge when all tests are passing label Apr 29, 2025
KristofferC pushed a commit that referenced this pull request May 5, 2025
@KristofferC KristofferC mentioned this pull request May 5, 2025
53 tasks
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label May 9, 2025
charleskawczynski pushed a commit to charleskawczynski/julia that referenced this pull request May 12, 2025
KristofferC pushed a commit that referenced this pull request Jun 25, 2025
@KristofferC KristofferC mentioned this pull request Aug 19, 2025
65 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 dates Dates, times, and the Dates stdlib module docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants