-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Issue 90788 improvments to System.Diagnostics.Stopwatch #90789
Conversation
Tagging subscribers to this area: @tommcdon Issue DetailsImplementation of changes suggested in Issue 90788 to System.Diagnostics.Stopwatch to improve when measuring small time periods.
|
@dotnet-policy-service agree |
if (elapsedUntilNow > 0) | ||
{ | ||
// When measuring small time periods the Stopwatch.Elapsed* | ||
// properties can return negative values. This is due to | ||
// bugs in the basic input/output system (BIOS) or the hardware | ||
// abstraction layer (HAL) on machines with variable-speed CPUs | ||
// (e.g. Intel SpeedStep). | ||
|
||
timeElapsed += elapsedUntilNow; | ||
} |
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.
We utilize the monotonic timers available from the underlying OS (QueryPerformanceCounter
on Windows, CLOCK_UPTIME_RAW
or CLOCK_MONOTONIC
on Unix) which have strict contracts around not going backwards,
We can have up to a 1ns resolution, in which case overflow would take ~292 years in the worst possible scenario.
Given the support lifecycle of .NET and pieces of hardware, I'd say you have many other problems if you've not restarted your machine in 292 years ;)
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.
The comment here (copied from the other place above) relates to much older fallback behavior that existed for very old systems before QPC
existed (back when we supported cases like Win98 or early Win2k machines).
Nowadays we require a high precision timer to exist and I don't expect that to change at any point in the future, so a simple assert is probably plenty fine.
Thanks for trying to improve things here. I think it'd be better to address #66734 by just deleting the relevant code. |
@andreas-synnerdahl thanks for contributing this PR to .NET! Please let us know if you plan to make the suggested code changes to the PR. Otherwise would you mind changing it to 'draft' mode? |
Hi @andreas-synnerdahl I've moved this PR to draft as there hasn't been much activity lately. Feel free to move it out of draft mode if you plan on addressing the feedback. |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Implementation of changes suggested in Issue 90788 to System.Diagnostics.Stopwatch to improve when measuring small time periods.