The average execution time

There is a performance function, but I am wondering how to accumulate results and display the average of the last 10 results in real-time.

GetPerformanceCounter(True); // reset counter to zero 
for( i = 0; i < 1000; i++ ) 
{ 
   k = sin( i ); 
} 
elapsed=GetPerformanceCounter(); 
_TRACE("Time [ms] = "+elapsed);

Just measure time of say 10 iterations and divide by 10.

GetPerformanceCounter(True); // reset counter to zero 
for( k = 0; k < 10; k++ )
  for( i = 0; i < 1000; i++ ) 
  { 
     k = sin( i ); 
  } 
elapsed=GetPerformanceCounter(); 
_TRACE("Avg Time [ms] = "+elapsed / k );

Yes, but I want to do it with a formula that refreshes every tick. Something similar to "Display chart timing", but there there is no information about "average Chart Timing" of recent x-events.

You can save/add the elapsed time into a static variable and have a static counter

#pragma enable_static_decl("{chartid}");
static runs;
static totaltime;

GetPerformanceCounter(True);

// code you would like to measure

elapsed=GetPerformanceCounter(); 

runs = Nz( runs ) + 1;
totaltime = Nz( totaltime ) + elapsed; 

str = StrFormat("Runs %g, AvgTime = %g ms\n", runs, totaltime/runs);

Title = str;

_TRACE( str );
4 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.