Search code examples
c#.netperformancestopwatch

How accurate is System.Diagnostics.Stopwatch?


How accurate is System.Diagnostics.Stopwatch? I am trying to do some metrics for different code paths and I need it to be exact. Should I be using stopwatch or is there another solution that is more accurate?

I have been told that sometimes stopwatch gives incorrect information.


Solution

  • Why don't you profile your code instead of focusing on microbenchmarks?

    There are some good open source profilers, like: