AverageTimer32 counter becomes zero

I wrote a code snippet as shown below:

For testing, I call the ComputeAndLog method and on the performance monitor I see an average value other than zero. However, as soon as I finish my testing, the average value of the performance counter drops to zero. Any idea why this is so?

Maybe I'm using the wrong counters?

The requirement that I have is that I have a function, and I have to calculate that on average how long it takes to execute this function. Something like below:

void ComputeAndLog()
{
    Stopwatch stopWatch = Stopwatch.StartNew();
    FunctionWhoseAveragetTimeIsToBeMeasured();
    write_counter(stopWatch.ElapsedTicks);
}

void write_counter(long timeForCompletion)
{
    averageTimeCounter.IncrementBy(timeForCompletion);
    averageBaseCounter.Increment();
}

Thanks xoxo

+5
source share
2 answers

AverageTimer32/64 . .

, , , .

, AverageTimer, , . , Timer .

AverageTimer :

((N1 - N0) / F) / (B1 - B0)

  • N1 t (AverageTimer)
  • N0 , t - 1 (AverageTimer)
  • B1 t ()
  • B0 , t - 1 ( )
  • F /

. , F, , , t-1.

. . .

, . , , . , , . , ( ).

, . , 10, 9, 8, 7, 6, 1.

, , :

(9 - 10)/F/(1 - 0) = -1/F/1

F 1, -1.

10, 19, 27, 34, 40

(19 - 10)/F/(1 - 0) = 9/F/1

, F 1, 9 . , , , AverageTimer .

. , , Start() (not Restart()). , . , .

, , , , . , Close() .

+4

. PerformanceMonitor AverangeCounter. NextValue 0. , ElapsedTime , , .

​​MiddleTimer32 (). , AverageTimer32 . , . , , 0 .

NextValue , , , ( , , . AverageTimer32 , ). , ( NextValue , 0).

.

10, 9, 8, 7, 6

10, 19, 27, 34, 40

IncreaseBy

10, 19, 27, 34, 40

"".GetTimestamp() RawValue.

0

All Articles