How to use AverageTimer32 and AverageBase performance counters with System.Diagnostics.Stopwatch?

前端 未结 3 1535
北恋
北恋 2021-02-02 10:15

When I execute the following program and look at the performance counter the results don\'t make sense to me. The average value is zero and the min/max values are ~0.4 when I w

3条回答
  •  佛祖请我去吃肉
    2021-02-02 10:48

    The System.Diagnostics API contains a pretty subtle source of great confusion: System.Diagnostics 'ticks' are not the same as DateTime or TimeSpan 'ticks'!

    If you use StopWatch.ElapsedTicks instead of StopWatch.Elapsed.Ticks, it should work.

    The documentation contains more information about this.

提交回复
热议问题