-
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
Stopwatch is inconsistent when guarding against negative Elapsed durations #66734
Comments
Tagging subscribers to this area: @tommcdon Issue Details
runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Stopwatch.cs Lines 63 to 72 in a1f1ab8
If this behavior is worth preserving for stopped I believe this logic should either be removed entirely, or apply to all overloads regardless of
|
If this was "due to bugs", is this even still an issue? I agree we should either delete the logic or make it apply everywhere. It doesn't make sense to only do this for stopped, if it's even needed. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue Details
runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Stopwatch.cs Lines 63 to 72 in a1f1ab8
If this behavior is worth preserving for stopped I believe this logic should either be removed entirely, or apply to all overloads regardless of I wouldn't be surprised if some of our own logic is not accounting for the possibility of negative durations.
|
Adjusted the label on this since |
We've switched to using exclusively monotonic timers for quite a while now and so I think this code is effectively "dead". We might need to confirm that same is true for Mono, but I believe its mostly all shared atm. |
Moving to future. The implementation is calling exclusively into 64-bit monotonic timers as of right now. It would be good to remove this now unnecessary logic and document the reasoning. The overflow rate for 1ns ticks is approx. 292 years, which is more than reasonable. |
Stopwatch
has the following code to detect negative elapsed durations, but this logic only runs during theStopwatch.Stop
call.runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Stopwatch.cs
Lines 63 to 72 in a1f1ab8
If this behavior is worth preserving for stopped
Stopwatch
instances, I don't see why the responsibility should be shifted to the caller for "active" ones.I believe this logic should either be removed entirely, or apply to all overloads regardless of
IsRunning
, possibly including the newGetElapsedTime
helpers.I wouldn't be surprised if some of our own logic is not accounting for the possibility of negative durations.
The text was updated successfully, but these errors were encountered: