Skip to content

utilities: array to fgl #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions utilities/common/utilities.arraysort.pas

This file was deleted.

99 changes: 58 additions & 41 deletions utilities/results_generator/Common/resultsgenerator.common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@ interface
uses
Classes
, SysUtils
, fgl
, Utilities.Data.Config
, Utilities.Data.Entries
, Utilities.Data.Hyperfine
;

type
{ TResults }

{ TResult }

TResult = class
Name: String;
Notes: String;
Compiler: String;
Result: Double;
Count: Integer;
constructor Create;
end;

TResultsList = specialize TFPGObjectList<TResult>;

{ TResults }

TResults = class(TObject)
private
FConfig: TConfig;
FResult: THyperfineResult;
FList: TResultsList;

function GenerateProgressBar(APBPosition, APBMax, APBWIdth: Integer): String;
function CompareResults(const elem1, elem2): Integer;
function FormatTime(ATime: Double): String;
protected
public
Expand All @@ -42,24 +58,32 @@ implementation
, Utilities.ArraySort
;

type
//PResult = ^TResult;
TResult = record
Name: TJSONStringType;
Notes: TJSONStringType;
Compiler: TJSONStringType;
Result: Double;
Count: Integer;
end;
TResultsArray = array of TResult;

const
lineBreak = #13;

cTableHeader =
'| # | Result (m:s.ms): SSD | Compiler | Submitter | Notes | Certificates |'#10 +
'|--:|---------------------:|:---------|:--------------|:----------|:-------------|'#10;

function CompareResults(const elem1, elem2: TResult): Integer;
begin
if elem1.Result = elem2.Result then Result:= 0
else if elem1.Result < elem2.Result then Result:= -1
else Result:= 1;
end;

{ TResult }

constructor TResult.Create;
begin
inherited Create;
Name := '';
Notes := '';
Compiler := '';
Result := 0;
Count := 0;
end;

{ TResults }

constructor TResults.Create(AConfigFile: String);
Expand All @@ -78,24 +102,16 @@ constructor TResults.Create(AConfigFile: String);
finally
configStream.Free;
end;
FList := TResultsList.Create;
end;

destructor TResults.Destroy;
begin
FConfig.Free;
FList.Free;
inherited Destroy;
end;

function TResults.CompareResults(const elem1, elem2): Integer;
var
i1 : TResult absolute elem1;
i2 : TResult absolute elem2;
begin
if i1.Result = i2.Result then Result:= 0
else if i1.Result < i2.Result then Result:= -1
else Result:= 1;
end;

function TResults.FormatTime(ATime: Double): String;
var
intPart, minutes: Integer;
Expand Down Expand Up @@ -127,11 +143,11 @@ procedure TResults.Generate;
var
index, index1, index2: Integer;
content, hyperfineFile: String;
results: TResultsArray;
resultitem: TResult;
hyperfineStream: TFileStream;
hyperfineJSON: TJSONData;
begin
SetLength(results, 0);
FList.Clear;

for index:= 0 to Pred(FConfig.Entries.Count) do
begin
Expand All @@ -142,8 +158,9 @@ procedure TResults.Generate;
'-1_000_000_000-SSD.json'
);
if not FileExists(hyperfineFile) then continue;
SetLength(results, Length(results) + 1);
index2:= Length(results) - 1;
resultitem := TResult.Create;
FList.Add(resultitem);
index2 := FList.Count - 1;
hyperfineStream:= TFileStream.Create(
hyperfineFile,
fmOpenRead
Expand All @@ -157,20 +174,20 @@ procedure TResults.Generate;
try
if FConfig.Entries[index].Compiler = 'fpc' then
begin
results[index2].Compiler:= 'lazarus-3.0, fpc-3.2.2';
FList[index2].Compiler:= 'lazarus-3.0, fpc-3.2.2';
end;

results[index2].Name:= FConfig.Entries[index].Name;
results[index2].Notes:= FConfig.Entries[index].Notes;
results[index2].Result:= 0.0;
results[index2].Count:= 0;
FList[index2].Name:= FConfig.Entries[index].Name;
FList[index2].Notes:= FConfig.Entries[index].Notes;
FList[index2].Result:= 0.0;
FList[index2].Count:= 0;
for index1:= Low(FResult.Times) to High(FResult.Times) do
begin
if (time = FResult.Max) or (time = FResult.Max) then continue;
results[index2].Result:= results[index2].Result + FResult.Times[index1];
Inc(results[index2].Count);
FList[index2].Result:= FList[index2].Result + FResult.Times[index1];
Inc(FList[index2].Count);
end;
results[index2].Result:= results[index2].Result / results[index2].Count;
FList[index2].Result:= FList[index2].Result / FList[index2].Count;
finally
FResult.Free;
end;
Expand All @@ -185,17 +202,17 @@ procedure TResults.Generate;
WriteLn;
WriteLn;

//AnySort(results, Length(results), SizeOf(TResult), @CompareResults);
FList.Sort(@CompareResults);

content:= '';
for index:= Low(results) to High(results) do
for index:= 0 to FList.Count - 1 do
begin
content:= content + Format('| %d | %s | %s | %s | %s | |'+LineEnding, [
index + 1,
FormatTime(results[index].Result),
results[index].Compiler,
results[index].Name,
results[index].Notes
FormatTime(FList[index].Result),
FList[index].Compiler,
FList[index].Name,
FList[index].Notes
]);
end;

Expand Down