Accuracy of System.Diagnostics.Stopwatch

  • Thread starter Thread starter Homer Simpson
  • Start date Start date
H

Homer Simpson

Does anyone have any experience and/or documentation concerning the accuracy
of the stopwatch class? How does it calculate the elapsed time? I read
somewhere Stopwatch could be used for performance testing of various methods
and would like to know how accurate it is.

Thanks,
Scott
 
It is as accurate as how accurate DateTime.Now is. As it Timespan between
two DateTimes. I would guess 0-50ms delta on average.
 
Scott,

Check the Stopwatch.Frequency field. It will return the number of
ticks per second. I suspect the class wraps the
QueryPerformanceCounter and QueryPerformanceFrequency APIs if there is
a high resolution hardware counter on the box so it's likely to be very
accurate.

Brian
 
Back
Top