Skip to content

Commit

Permalink
Merge pull request #1218 from AndreyAkinshin/master
Browse files Browse the repository at this point in the history
Suppression of negative Elapsed in Stopwatch, this is the comment from the Reference Source:

                    // 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).
  • Loading branch information
migueldeicaza committed Sep 23, 2015
2 parents 28f473c + 45d5332 commit 226af94
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mcs/class/System/System.Diagnostics/Stopwatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public void Stop ()
if (!is_running)
return;
elapsed += GetTimestamp () - started;
if (elapsed < 0)
elapsed = 0;
is_running = false;
}

Expand Down

0 comments on commit 226af94

Please sign in to comment.