Skip to content

Commit 53560e7

Browse files
committed
feat: Results Table Generator before sort
1 parent e5581e8 commit 53560e7

File tree

6 files changed

+271
-31
lines changed

6 files changed

+271
-31
lines changed

utilities/common/utilities.data.entries.pas

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ interface
3434
TEntry = class(TObject)
3535
private
3636
FActive: Boolean;
37-
FName: String;
38-
FNotes: String;
39-
FCompiler: String;
40-
FEntryFolder: String;
41-
FEntryBinary: String;
42-
FLPI: String;
37+
FName: TJSONStringType;
38+
FNotes: TJSONStringType;
39+
FCompiler: TJSONStringType;
40+
FEntryFolder: TJSONStringType;
41+
FEntryBinary: TJSONStringType;
42+
FLPI: TJSONStringType;
4343
FHasRelease: Boolean;
4444
FThreads: Integer;
45-
FRunParams: String;
45+
FRunParams: TJSONStringType;
4646

4747
//procedure setFromJSON(const AJSON: TJSONStringType);
4848
procedure setFromJSONData(const AJSONData: TJSONData);
@@ -58,22 +58,22 @@ TEntry = class(TObject)
5858
property Active: Boolean
5959
read FActive
6060
write FActive;
61-
property Name: String
61+
property Name: TJSONStringType
6262
read FName
6363
write FName;
64-
property Notes: String
64+
property Notes: TJSONStringType
6565
read FNotes
6666
write FNotes;
67-
property Compiler: String
67+
property Compiler: TJSONStringType
6868
read FCompiler
6969
write FCompiler;
70-
property EntryFolder: String
70+
property EntryFolder: TJSONStringType
7171
read FEntryFolder
7272
write FEntryFolder;
73-
property EntryBinary: String
73+
property EntryBinary: TJSONStringType
7474
read FEntryBinary
7575
write FEntryBinary;
76-
property LPI: String
76+
property LPI: TJSONStringType
7777
read FLPI
7878
write FLPI;
7979
property HasRelease: Boolean
@@ -82,7 +82,7 @@ TEntry = class(TObject)
8282
property Threads: Integer
8383
read FThreads
8484
write FThreads;
85-
property RunParams: String
85+
property RunParams: TJSONStringType
8686
read FRunParams
8787
write FRunParams;
8888
published
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
unit Utilities.Data.Hyperfine;
2+
3+
{$mode ObjFPC}{$H+}
4+
5+
interface
6+
7+
uses
8+
Classes
9+
, SysUtils
10+
, fpjson
11+
;
12+
13+
const
14+
cJSONHyperfineResult = 'results[0]';
15+
16+
type
17+
{ EResultNotAJSONObject }
18+
EResultNotAJSONObject = Exception;
19+
20+
{ THyperfineResult }
21+
TArrayOfTime = array of Double;
22+
THyperfineResult = class(TObject)
23+
private
24+
FCommand: String;
25+
FMean: Double;
26+
FStandardDeviation: Double;
27+
FMedian: Double;
28+
FUser: Double;
29+
FSystem: Double;
30+
FMin: Double;
31+
FMax: Double;
32+
FTimes: TArrayOfTime;
33+
34+
procedure setFromJSONData(const AJSONData: TJSONData);
35+
procedure setFromJSONObject(const AJSONObject: TJSONObject);
36+
protected
37+
public
38+
constructor Create;
39+
constructor Create(const AJSONData: TJSONData);
40+
41+
destructor Destroy; override;
42+
43+
property Command: String
44+
read FCommand
45+
write FCommand;
46+
property Mean: Double
47+
read fMean
48+
write FMean;
49+
property StandardDeviation: Double
50+
read FStandardDeviation
51+
write FStandardDeviation;
52+
property Median: Double
53+
read FMedian
54+
write FMedian;
55+
property User: Double
56+
read FUser
57+
write FUser;
58+
property System: Double
59+
read FSystem
60+
write FSystem;
61+
property Min: Double
62+
read FMin
63+
write FMin;
64+
property Max: Double
65+
read FMax
66+
write FMax;
67+
property Times: TArrayOfTime
68+
read FTimes
69+
write FTimes;
70+
published
71+
end;
72+
73+
implementation
74+
75+
const
76+
cJSONCommand = 'command';
77+
cJSONMean = 'mean';
78+
cJSONStandardDeviation = 'stddev';
79+
cJSONMedian = 'median';
80+
cJSONUser = 'user';
81+
cJSONSystem = 'system';
82+
cJSONMin = 'min';
83+
cJSONMax = 'max';
84+
cJSONTimes = 'times';
85+
86+
resourcestring
87+
rsExceptionNotAJSONObject = 'JSON Data is not an object';
88+
89+
{ THyperfineResult }
90+
91+
constructor THyperfineResult.Create;
92+
begin
93+
FCommand:= '';
94+
FMean:= 0.0;
95+
FStandardDeviation:= 0.0;
96+
FMedian:= 0.0;
97+
FUser:= 0.0;
98+
FSystem:= 0.0;
99+
FMin:= 0.0;
100+
FMax:= 0.0;
101+
SetLength(FTimes, 0);
102+
end;
103+
104+
constructor THyperfineResult.Create(const AJSONData: TJSONData);
105+
begin
106+
Create;
107+
setFromJSONData(AJSONData);
108+
end;
109+
110+
destructor THyperfineResult.Destroy;
111+
begin
112+
inherited Destroy;
113+
end;
114+
115+
procedure THyperfineResult.setFromJSONData(const AJSONData: TJSONData);
116+
begin
117+
if aJSONData.JSONType <> jtObject then
118+
begin
119+
raise EResultNotAJSONObject.Create(rsExceptionNotAJSONObject);
120+
end;
121+
setFromJSONObject(aJSONData as TJSONObject);
122+
end;
123+
124+
procedure THyperfineResult.setFromJSONObject(const AJSONObject: TJSONObject);
125+
var
126+
timesObject: TJSONArray;
127+
index: Integer;
128+
begin
129+
FCommand:= AJSONObject.Get(cJSONCommand, FCommand);
130+
FMean:= AJSONObject.Get(cJSONMean, FMean);
131+
FStandardDeviation:= AJSONObject.Get(cJSONStandardDeviation, FStandardDeviation);
132+
FMedian:= AJSONObject.Get(cJSONMedian, FMedian);
133+
FUser:= AJSONObject.Get(cJSONUser, FUser);
134+
FSystem:= AJSONObject.Get(cJSONSystem, FSystem);
135+
FMin:= AJSONObject.Get(cJSONMin, FMin);
136+
FMax:= AJSONObject.Get(cJSONMax, FMax);
137+
timesObject:= AJSONObject.Arrays[cJSONTimes];
138+
SetLength(FTimes, timesObject.Count);
139+
for index:= 0 to Pred(timesObject.Count) do
140+
begin
141+
FTimes[index]:= timesObject[index].AsFloat;
142+
end;
143+
end;
144+
145+
end.
146+

utilities/results_generator/Common/resultsgenerator.common.pas

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,55 @@ interface
1111
, SysUtils
1212
, Utilities.Data.Config
1313
, Utilities.Data.Entries
14+
, Utilities.Data.Hyperfine
1415
;
1516

1617
type
1718
{ TResults }
1819
TResults = class(TObject)
1920
private
2021
FConfig: TConfig;
22+
FResult: THyperfineResult;
2123

2224
function GenerateProgressBar(APBPosition, APBMax, APBWIdth: Integer): String;
2325
protected
2426
public
2527
constructor Create(AConfigFile: String);
2628
destructor Destroy; override;
2729

28-
{$IFDEF UNIX}
29-
{$ELSE}
30-
{$ENDIF}
30+
procedure Generate;
3131
published
3232
end;
3333

3434
implementation
3535

3636
uses
37-
{$IFDEF FPC}
3837
fpjson
3938
, jsonparser
40-
{$ELSE}
41-
{$ENDIF}
4239
;
4340

4441
const
4542
lineBreak = #13;
4643

44+
cTableHeader =
45+
'| # | Result (m:s.ms): SSD | Compiler | Submitter | Notes | Certificates |'#10 +
46+
'|--:|---------------------:|:---------|:--------------|:----------|:-------------|'#10;
47+
4748
{ TResults }
4849

4950
constructor TResults.Create(AConfigFile: String);
5051
var
5152
configStream: TFileStream;
5253
configJSONData: TJSONData;
5354
begin
54-
{ #todo 99 -ogcarreno : Config file must be used here }
5555
configStream:= TFileStream.Create(AConfigFile, fmOpenRead);
5656
try
5757
configJSONData:= GetJSON(configStream);
58-
FConfig:= TConfig.Create(configJSONData);
59-
configJSONData.Free;
58+
try
59+
FConfig:= TConfig.Create(configJSONData);
60+
finally
61+
configJSONData.Free;
62+
end;
6063
finally
6164
configStream.Free;
6265
end;
@@ -68,6 +71,85 @@ destructor TResults.Destroy;
6871
inherited Destroy;
6972
end;
7073

74+
procedure TResults.Generate;
75+
type
76+
TResult = record
77+
Result: Double;
78+
Count: Integer;
79+
Compiler: String;
80+
end;
81+
TResultsArray = array of TResult;
82+
83+
var
84+
index, index1: Integer;
85+
content, hyperfineFile: String;
86+
results: TResultsArray;
87+
hyperfineStream: TFileStream;
88+
hyperfineJSON: TJSONData;
89+
begin
90+
content:= '';
91+
SetLength(results, FConfig.Entries.Count);
92+
93+
for index:= 0 to Pred(FConfig.Entries.Count) do
94+
begin
95+
Write(GenerateProgressBar(Succ(index), FConfig.Entries.Count, 50), lineBreak);
96+
hyperfineFile:= ExpandFileName(
97+
IncludeTrailingPathDelimiter(FConfig.ResultsFolder)+
98+
FConfig.Entries[index].EntryBinary+
99+
'-1_000_000_000-SSD.json'
100+
);
101+
if not FileExists(hyperfineFile) then continue;
102+
hyperfineStream:= TFileStream.Create(
103+
hyperfineFile,
104+
fmOpenRead
105+
);
106+
try
107+
hyperfineJSON:= GetJSON(hyperfineStream);
108+
try
109+
FResult:= THyperfineResult.Create(
110+
hyperfineJSON.GetPath(cJSONHyperfineResult)
111+
);
112+
try
113+
if FConfig.Entries[index].Compiler = 'fpc' then
114+
begin
115+
results[index].Compiler:= 'lazarus-3.0, fpc-3.2.2';
116+
end;
117+
118+
results[index].Result:= 0.0;
119+
results[index].Count:= 0;
120+
for index1:= Low(FResult.Times) to High(FResult.Times) do
121+
begin
122+
if (time = FResult.Max) or (time = FResult.Max) then continue;
123+
results[index].Result:= results[index].Result + FResult.Times[index1];
124+
Inc(results[index].Count);
125+
end;
126+
results[index].Result:= results[index].Result / results[index].Count;
127+
{ #todo 99 -ogcarreno : needs to be done after sorting array by time }
128+
content:= content + Format('| %d | %.2f | %s | %s | %s | |'+LineEnding, [
129+
index,
130+
results[index].Result,
131+
results[index].Compiler,
132+
FConfig.Entries[index].Name,
133+
FConfig.Entries[index].Notes
134+
]);
135+
finally
136+
FResult.Free;
137+
end;
138+
finally
139+
hyperfineJSON.Free;
140+
end;
141+
finally
142+
hyperfineStream.Free;
143+
end;
144+
end;
145+
146+
WriteLn;
147+
WriteLn;
148+
Write(cTableHeader, content);
149+
// The results
150+
WriteLn;
151+
end;
152+
71153
function TResults.GenerateProgressBar(APBPosition, APBMax, APBWIdth: Integer
72154
): String;
73155
var

utilities/results_generator/Lazarus/src/resultsgenerator.lpi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<RunParams>
8686
<FormatVersion Value="2"/>
8787
</RunParams>
88-
<Units Count="5">
88+
<Units Count="6">
8989
<Unit0>
9090
<Filename Value="resultsgenerator.lpr"/>
9191
<IsPartOfProject Value="True"/>
@@ -104,11 +104,18 @@
104104
<Unit3>
105105
<Filename Value="../../../common/utilities.data.config.pas"/>
106106
<IsPartOfProject Value="True"/>
107+
<UnitName Value="Utilities.Data.Config"/>
107108
</Unit3>
108109
<Unit4>
109110
<Filename Value="../../../common/utilities.data.entries.pas"/>
110111
<IsPartOfProject Value="True"/>
112+
<UnitName Value="Utilities.Data.Entries"/>
111113
</Unit4>
114+
<Unit5>
115+
<Filename Value="../../../common/utilities.data.hyperfine.pas"/>
116+
<IsPartOfProject Value="True"/>
117+
<UnitName Value="Utilities.Data.Hyperfine"/>
118+
</Unit5>
112119
</Units>
113120
</ProjectOptions>
114121
<CompilerOptions>

0 commit comments

Comments
 (0)