Want to show your appreciation?
Please a cup of tea.

Monday, June 08, 2009

Watch out for the .Net Stopwatch, ElapsedTicks != Elapsed.Ticks

Well, I was assuming that the Stopwatch returns ElapsedTicks measuring 1tick = 100ns as TimeSpan.Ticks does. Wasted more then an hour trying to debug a test case for multi-threaded application to find out that this is not the case. In order to get the measurement at the unit of 100ns, I need to use Stopwatch.Elapsed.Ticks!

Here is from the documentation:

Stopwatch ticks are different from DateTime.Ticks. Each tick in the DateTime.Ticks value represents one 100-nanosecond interval. Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

Also, an good article about time measuring: Beware of the stopwatch

No comments:

Post a Comment