unit Unit1;
interface uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Diagnostics,
System.Threading,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
FMX.Edit,
FMX.EditBox,
FMX.SpinBox,
FMX.Layouts,
FMX.ListBox,
FMX.StdCtrls,
FMX.Controls.Presentation;
type
T3DFloatArray = TArray<TArray<TArray<Double>>>;
TForm1 =
class(TForm)
Button1: TButton;
ListBox1: TListBox;
SpinBox1: TSpinBox;
SpinBox2: TSpinBox;
isMultiThreadedCheckbox: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private var
stopwatch1, stopwatch2: TStopWatch;
private
class function NotRandom(): Double;
inline;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
testDataDimensionCount: Integer;
iterationCount: Integer;
count, zz: Integer;
testdata: T3DFloatArray;
testProcedure: TProc<Integer>;
begin
testDataDimensionCount := Round(SpinBox1.Value);
iterationCount := Round(SpinBox2.Value);
ListBox1.Clear();
stopwatch1 := TStopwatch.StartNew();
setlength(testdata, testDataDimensionCount, testDataDimensionCount, testDataDimensionCount);
stopwatch1.Stop();
ListBox1.Items.Add('
get-mem: ' + inttostr(stopwatch1.ElapsedMilliseconds) + '
ms');
testProcedure :=
procedure(_zz: Integer)
var
_xx, _yy: Integer;
begin
for _yy := 0
to testDataDimensionCount - 1
do
for _xx := 0
to testDataDimensionCount - 1
do
testdata[zz, _yy, _xx] := NotRandom();
end;
stopwatch2 := TStopwatch.StartNew();
for count := 0
to iterationCount - 1
do
begin
stopwatch1 := TStopwatch.StartNew();
if isMultiThreadedCheckbox.IsChecked
then
begin
TParallel.&
For(
0,
testDataDimensionCount - 1,
testProcedure
);
end
else
begin
for zz := 0
to testDataDimensionCount - 1
do
testProcedure(zz);
end;
stopwatch1.Stop();
ListBox1.Items.Add('
[' + inttostr(count) + '
]: ' + inttostr(stopwatch1.ElapsedMilliseconds) + '
ms');
end;
stopwatch2.Stop;
ListBox1.Items.Add('
-> done: ' + inttostr(stopwatch2.ElapsedMilliseconds) + '
ms');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
end;
class function TForm1.NotRandom(): Double;
begin
Result := 42.0;
end;
end.