Search code examples
.netperformanceperformancecounterdiagnosticsperfmon

What is the most appropriate performance counter type for measuring operation time?


Say I have a method Foo() and I want to measure the time in milliseconds it took to execute which type of Windows Performance Counter should I be using?

var stopwatch = new Stopwatch();
stopwatch.Start();
Foo();
stopwatch.Stop();
counter.RawValue = stopwatch.TotalMilliseonds;

Currently I'm using NumberOfItems64 but that persists the last value of the counter unless the new operation is performed. Is it desirable? Or should the counter go to zero as soon as the operation is done? Which counter type would you choose in this situation and why?


Solution

  • This sounds like a good candidate for AverageTimer32. See this SO answer for more details.