I see a discrepancy in the benchmarks I run between "code check & profile" and the GetPerformanceCounter( ).
Here is the code I run (in 1m timeframe, the database base interval):
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
B1 = SelectedValue( BarIndex() );
B2 = BarCount -1;
Lv = SelectedValue( L );
Hv = SelectedValue( H );
Pv = Lv - (Hv-Lv);
loopnum = 497;
GetPerformanceCounter( True ); // reset counter to zero
for ( i = 1;i <= loopnum;i++ )
{
tmpLine = LineArray( B1, Lv, B2, Lv, 1 );
Plot( tmpLine, "Low", colorBlue, styleLine | styleNoRescale );
}
t1 = GetPerformanceCounter();
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)
GfxSelectPen( colorBlue );
GetPerformanceCounter( True ); // reset counter to zero
for ( i = 1;i <= loopnum;i++ )
{
GfxMoveTo( B1, Hv );
GfxLineTo( B2, Hv );
}
t2 = GetPerformanceCounter();
GetPerformanceCounter( True ); // reset counter to zero
for ( i = 1;i <= loopnum;i++ )
{
PlotGrid( Pv, colorBlue, 10, 1, true );
}
t3 = GetPerformanceCounter();
printf( "LineArray time (ms): " + numtostr( t1 ) + "\n" );
printf( "GfxLineTo time (ms):" + numtostr( t2 ) + "\n" );
printf( "PlotGrid time (ms):" + numtostr( t3 ) + "\n" );
printf( "diff1 (ms): " + NumToStr( t1 - t2, 1.4 ) + "\n" );
printf( "diff2 (ms): " + NumToStr( t1 - t3, 1.4 ) + "\n" );
This is the output:
LineArray time (ms): 2.646
GfxLineTo time (ms): 0.213
PlotGrid time (ms): 0.371
diff1 (ms): 2.4336
diff2 (ms): 2.2752
So total execution time should be a little above 3ms.
This is what Code Check & Profile reports:
This is more that 48ms, about 15 times more.
More specifically, the 1st method reports that the Gfx method is a lot faster than the PlotGrid. However the second method reports that GfxMoveTo+GfxLineTo is a little slower than PlotGrid.
Am I doing something wrong ?