OptimizationOn property
|
Top Previous Next |
Unit
Applies to
Declaration property OptimizationOn : boolean default true ;
Description
Set OptimizationOn to let the bcParser component evaluate constant expressions at parse time. The optimized parse tree will enhance subsequant evaluation operations, though initial parsing will be slower.
Optimization is good if you are going to parse once and evaluate the same expression many many times with different variable values.
When OptimizationOn is true, following code runs in 170 milliseconds. When Optimization is false, following code runs in 220 milliseconds on PII 300.
procedure TForm1.bbCalcClick(Sender: TObject); var i: integer; count: integer; begin bcParser.Expression := 'SIN(3.14)+5^2+POW(2,7)-MAX(10,20)';
count:= GetTickCount; try for i:= 1 to 10000 do begin bcParser.X := i*2; bcParser.Y := i/2; labResult.Caption := FloatToStr(bcParser.Parse); end; except on e: Exception do ShowMessage(e.Message); end;
ShowMessage(FloatToStr(GetTickCount - count)); end;
|