-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Closed
Copy link
Labels
area-System.Runtimebugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Stopwatch has the following code to detect negative elapsed durations, but this logic only runs during the Stopwatch.Stop call.
runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Stopwatch.cs
Lines 63 to 72 in a1f1ab8
| if (_elapsed < 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). | |
| _elapsed = 0; | |
| } |
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 new GetElapsedTime helpers.
I wouldn't be surprised if some of our own logic is not accounting for the possibility of negative durations.
Metadata
Metadata
Assignees
Labels
area-System.Runtimebugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged