Page 1 of 1

How to benchmark TChart recalc / redraw times?

Posted: Fri Apr 23, 2021 10:36 am
by 17591001
Hello all,

I'd like to benchmark the times required for adding points to a TLineSeries and the actual time consumed during redraw. If I understand correctly, the redrawing is performed in next call to message loop.

Is there an example how to benchmark the redraw performance?

Best regards,
Focus

Re: How to benchmark TChart recalc / redraw times?

Posted: Mon Apr 26, 2021 9:13 am
by yeray
Hello,

You can start a TStopWatch at the Chart's OnBeforeDraw event calculate the elapsed time at OnAfterDraw event. Ie:

Code: Select all

uses Diagnostics, TimeSpan;

var stopWatch: TStopwatch;

procedure TForm1.ChartBeforeDraw(Sender: TObject);
begin
  label1.Caption:='Drawing...';
  stopWatch:=TStopwatch.Create;
  stopWatch.Start;
end;

procedure TForm1.ChartAfterDraw(Sender: TObject);
var elapsed: TTimeSpan;
    seconds: Double;
begin
  elapsed:=stopWatch.Elapsed;
  seconds:=elapsed.TotalSeconds;
  label1.Caption:='Drawing took ' + FormatFloat('#,##0.##', seconds) + ' seconds';
end;