Skip to content

Commit

Permalink
Beta 15
Browse files Browse the repository at this point in the history
  • Loading branch information
David Berneda committed Aug 3, 2016
1 parent 7bf8dab commit 18ed19d
Show file tree
Hide file tree
Showing 92 changed files with 2,190 additions and 1,117 deletions.
18 changes: 15 additions & 3 deletions demos/delphi/TeeBI_Delphi_Demos.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Projects Include="vcl\TeeChart\Import Series\TeeBI_Import_TeeChart_Series.dproj">
<Dependencies/>
</Projects>
<Projects Include="vcl\Query\Select_Queries\TeeBI_Select_Queries.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Default.Personality.12</Borland.Personality>
Expand Down Expand Up @@ -155,14 +158,23 @@
<Target Name="TeeBI_Import_TeeChart_Series:Make">
<MSBuild Projects="vcl\TeeChart\Import Series\TeeBI_Import_TeeChart_Series.dproj" Targets="Make"/>
</Target>
<Target Name="TeeBI_Select_Queries">
<MSBuild Projects="vcl\Query\Select_Queries\TeeBI_Select_Queries.dproj"/>
</Target>
<Target Name="TeeBI_Select_Queries:Clean">
<MSBuild Projects="vcl\Query\Select_Queries\TeeBI_Select_Queries.dproj" Targets="Clean"/>
</Target>
<Target Name="TeeBI_Select_Queries:Make">
<MSBuild Projects="vcl\Query\Select_Queries\TeeBI_Select_Queries.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="TeeBI_Grid_Demo;TeeBI_Import_Demo;TeeBI_DataSearch_Demo;TeeBI_Speed;TeeBI_Grid_Demo_FMX;BIDataSet_Speed;MasterDetail_BIDataSet;TeeBI_Export;TeeBI_PDF_Export;TeeBI_Expressions_Test;TeeBI_ORM_RTTI_Example;TeeBI_Import_TeeChart_Series"/>
<CallTarget Targets="TeeBI_Grid_Demo;TeeBI_Import_Demo;TeeBI_DataSearch_Demo;TeeBI_Speed;TeeBI_Grid_Demo_FMX;BIDataSet_Speed;MasterDetail_BIDataSet;TeeBI_Export;TeeBI_PDF_Export;TeeBI_Expressions_Test;TeeBI_ORM_RTTI_Example;TeeBI_Import_TeeChart_Series;TeeBI_Select_Queries"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="TeeBI_Grid_Demo:Clean;TeeBI_Import_Demo:Clean;TeeBI_DataSearch_Demo:Clean;TeeBI_Speed:Clean;TeeBI_Grid_Demo_FMX:Clean;BIDataSet_Speed:Clean;MasterDetail_BIDataSet:Clean;TeeBI_Export:Clean;TeeBI_PDF_Export:Clean;TeeBI_Expressions_Test:Clean;TeeBI_ORM_RTTI_Example:Clean;TeeBI_Import_TeeChart_Series:Clean"/>
<CallTarget Targets="TeeBI_Grid_Demo:Clean;TeeBI_Import_Demo:Clean;TeeBI_DataSearch_Demo:Clean;TeeBI_Speed:Clean;TeeBI_Grid_Demo_FMX:Clean;BIDataSet_Speed:Clean;MasterDetail_BIDataSet:Clean;TeeBI_Export:Clean;TeeBI_PDF_Export:Clean;TeeBI_Expressions_Test:Clean;TeeBI_ORM_RTTI_Example:Clean;TeeBI_Import_TeeChart_Series:Clean;TeeBI_Select_Queries:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="TeeBI_Grid_Demo:Make;TeeBI_Import_Demo:Make;TeeBI_DataSearch_Demo:Make;TeeBI_Speed:Make;TeeBI_Grid_Demo_FMX:Make;BIDataSet_Speed:Make;MasterDetail_BIDataSet:Make;TeeBI_Export:Make;TeeBI_PDF_Export:Make;TeeBI_Expressions_Test:Make;TeeBI_ORM_RTTI_Example:Make;TeeBI_Import_TeeChart_Series:Make"/>
<CallTarget Targets="TeeBI_Grid_Demo:Make;TeeBI_Import_Demo:Make;TeeBI_DataSearch_Demo:Make;TeeBI_Speed:Make;TeeBI_Grid_Demo_FMX:Make;BIDataSet_Speed:Make;MasterDetail_BIDataSet:Make;TeeBI_Export:Make;TeeBI_PDF_Export:Make;TeeBI_Expressions_Test:Make;TeeBI_ORM_RTTI_Example:Make;TeeBI_Import_TeeChart_Series:Make;TeeBI_Select_Queries:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
238 changes: 201 additions & 37 deletions demos/delphi/firemonkey/Expressions/BI.Expression.Benchmark.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,57 @@

interface

{$IFNDEF FPC}
{$IF CompilerVersion>27}
{$DEFINE THREADING} // RAD XE7 and up
{$ENDIF}
{$ENDIF}

uses
System.Classes, BI.Expression;

// TExpression benchmark speed.
// Parse and evaluate all test expressions multiple times.

type
TBenchMode=(Evaluate,Parse,Both);

TBenchmark=record
private

function Parse(const S:String):TExpression;

{$IFDEF THREADING}
procedure BothMulti;
procedure EvaluateMulti;
procedure ParseMulti;
procedure RunMultiCPU;
{$ENDIF}
procedure RunSingleCPU;
public
const
BenchmarkCount=100000;
BenchmarkCount=10000;

var
Expressions : TArray<TExpression>;
Expressions : TExpressions;

UseThreads : Boolean;

Items : TStrings;

Total,
Count :Integer;

Mode : TBenchMode;

Creating,
Evaluating : Int64;
Testing : Int64;

procedure DestroyAll;
procedure EvaluateAll;
procedure Initialize(const AItems:TStrings);
procedure Initialize(const AItems:TStrings; const MultiCPU:Boolean; const AMode:TBenchMode);
procedure ParseAll;
procedure ShowResults(const ALines:TStrings);
procedure TestAll;
end;

// Returns the S sub-strings at left and right of "->" symbol
Expand All @@ -41,33 +67,57 @@ function SplitTest(const S:String; out Left,Right:String):Boolean;
implementation

uses
{$IFDEF THREADING}
System.Threading,
{$ENDIF}
System.SysUtils, System.Diagnostics;

procedure TBenchmark.Initialize(const AItems:TStrings);
var t1 : TStopWatch;
t : Integer;

Left,
function TBenchmark.Parse(const S:String):TExpression;
var Left,
Right : String;
S : String;
begin
t1:=TStopwatch.StartNew;
if (S='') or (not SplitTest(S,Left,Right)) then
result:=nil
else
result:=TExpression.FromString(Left);
end;

SetLength(Expressions,AItems.Count);
procedure TBenchmark.ParseAll;
var t : Integer;
tmp : TExpression;
begin
DestroyAll;

Count:=0;

for t:=0 to AItems.Count-1 do
for t:=0 to Items.Count-1 do
begin
S:=AItems[t];

if S<>'' then
if SplitTest(S,Left,Right) then
begin
Expressions[Count]:=TExpression.FromString(Left);
Inc(Count);
end;
tmp:=Parse(Items[t]);

if tmp<>nil then
begin
Expressions[Count]:=tmp;
Inc(Count);
end;
end;
end;

procedure TBenchmark.Initialize(const AItems:TStrings;
const MultiCPU:Boolean;
const AMode:TBenchMode);
var t1 : TStopWatch;
begin
t1:=TStopwatch.StartNew;

Items:=AItems;

UseThreads:=MultiCPU;

SetLength(Expressions,Items.Count);

Mode:=AMode;

ParseAll;

Creating:=t1.ElapsedMilliseconds;

Expand All @@ -82,40 +132,154 @@ procedure TBenchmark.DestroyAll;
Expressions[t].Free;
end;

procedure TBenchmark.EvaluateAll;
{$IFDEF THREADING}

procedure TBenchmark.ParseMulti;
var tmpBench : TBenchmark;
begin
tmpBench:=Self;

TParallel.For(0,High(Expressions),procedure(Index:Integer)
var tmp : TExpression;
t : Integer;
S : String;
begin
S:=tmpBench.Items[Index];

for t:=1 to BenchmarkCount do
begin
tmp:=tmpBench.Parse(S);
tmp.Free;
end
end);
end;

procedure TBenchmark.EvaluateMulti;
var tmpExp: TExpressions;
begin
tmpExp:=Expressions;

TParallel.For(0,High(Expressions),procedure(Index:Integer)
var tmp : TExpression;
tmpResult : TData;
t : Integer;
begin
tmp:=tmpExp[Index];

for t:=1 to BenchmarkCount do
tmpResult:=tmp.Value;
end);
end;

procedure TBenchmark.BothMulti;
var tmpBench : TBenchmark;
begin
tmpBench:=Self;

TParallel.For(0,High(Expressions),procedure(Index:Integer)
var tmp : TExpression;
tmpResult : TData;
t : Integer;
S : String;
begin
S:=tmpBench.Items[Index];

for t:=1 to BenchmarkCount do
begin
tmp:=tmpBench.Parse(S);
tmpResult:=tmp.Value;
tmp.Free;
end;
end);
end;

procedure TBenchmark.RunMultiCPU;
begin
if Mode=TBenchMode.Parse then
ParseMulti
else
if Mode=TBenchMode.Evaluate then
EvaluateMulti
else
BothMulti;
end;
{$ENDIF}

procedure TBenchmark.RunSingleCPU;

procedure Test(const AExpression:TExpression);
var tmp : TData;
t : Integer;
begin
for t:=1 to BenchmarkCount do
tmp:=AExpression.Value;
end;

procedure LoopParseAll;
var t : Integer;
begin
for t:=1 to BenchmarkCount do
ParseAll;
end;

procedure EvaluateAll;
var t : Integer;
begin
for t:=0 to High(Expressions) do
Test(Expressions[t]);
end;

begin
if Mode=TBenchMode.Evaluate then
EvaluateAll
else
if Mode=TBenchMode.Parse then
LoopParseAll
else
begin
LoopParseAll;
EvaluateAll;
end;
end;

procedure TBenchmark.TestAll;
var t1 : TStopWatch;
tmpResult : Variant;
H,
t,
tt : Integer;
begin
t1:=TStopwatch.StartNew;

H:=High(Expressions);

for t:=1 to BenchmarkCount do
for tt:=0 to H do
tmpResult:=Expressions[tt].Value;
{$IFDEF THREADING}
if UseThreads then
RunMultiCPU
else
{$ENDIF}
RunSingleCPU;

Evaluating:=t1.ElapsedMilliseconds;
Testing:=t1.ElapsedMilliseconds;
end;

procedure TBenchmark.ShowResults(const ALines:TStrings);
var tmp : String;
begin
ALines.BeginUpdate;
try
ALines.Clear;

ALines.Add('Total creating time: '+Creating.ToString);
ALines.Add('Total evaluating time: '+Evaluating.ToString);
ALines.Add('Total testing time: '+Testing.ToString);

ALines.Add('Iterations: '+IntToStr(BenchmarkCount)+' expressions: '+IntToStr(Length(Expressions)));
ALines.Add('Iterations: '+BenchmarkCount.ToString+' expressions: '+Length(Expressions).ToString);

Total:=BenchmarkCount*Length(Expressions);

ALines.Add('Total evaluated: '+FormatFloat('#,##0',Total));
case Mode of
TBenchMode.Evaluate: tmp:='evaluated';
TBenchMode.Parse: tmp:='parsed';
TBenchMode.Both: tmp:='parsed and evaluated';
end;

ALines.Add('Total '+tmp+': '+FormatFloat('#,##0',Total));

ALines.Add('Average per eval: '+FormatFloat('0.#######',Evaluating / Total)+' msec.');
ALines.Add('Average per item: '+FormatFloat('0.#######',Testing / Total)+' msec.');
finally
ALines.EndUpdate;
end;
Expand Down
Loading

0 comments on commit 18ed19d

Please sign in to comment.