@@ -9,20 +9,36 @@ interface
99uses
1010 Classes
1111, SysUtils
12+ , fgl
1213, Utilities.Data.Config
1314, Utilities.Data.Entries
1415, Utilities.Data.Hyperfine
1516;
1617
1718type
18- { TResults }
19+
20+ { TResult }
21+
22+ TResult = class
23+ Name : String;
24+ Notes: String;
25+ Compiler: String;
26+ Result: Double;
27+ Count: Integer;
28+ constructor Create;
29+ end ;
30+
31+ TResultsList = specialize TFPGObjectList<TResult>;
32+
33+ { TResults }
34+
1935 TResults = class (TObject)
2036 private
2137 FConfig: TConfig;
2238 FResult: THyperfineResult;
39+ FList: TResultsList;
2340
2441 function GenerateProgressBar (APBPosition, APBMax, APBWIdth: Integer): String;
25- function CompareResults (const elem1, elem2): Integer;
2642 function FormatTime (ATime: Double): String;
2743 protected
2844 public
@@ -42,24 +58,32 @@ implementation
4258, Utilities.ArraySort
4359;
4460
45- type
46- // PResult = ^TResult;
47- TResult = record
48- Name : TJSONStringType;
49- Notes: TJSONStringType;
50- Compiler: TJSONStringType;
51- Result: Double;
52- Count: Integer;
53- end ;
54- TResultsArray = array of TResult;
55-
5661const
5762 lineBreak = #13 ;
5863
5964 cTableHeader =
6065 ' | # | Result (m:s.ms): SSD | Compiler | Submitter | Notes | Certificates |' #10 +
6166 ' |--:|---------------------:|:---------|:--------------|:----------|:-------------|' #10 ;
6267
68+ function CompareResults (const elem1, elem2: TResult): Integer;
69+ begin
70+ if elem1.Result = elem2.Result then Result:= 0
71+ else if elem1.Result < elem2.Result then Result:= -1
72+ else Result:= 1 ;
73+ end ;
74+
75+ { TResult }
76+
77+ constructor TResult.Create;
78+ begin
79+ inherited Create;
80+ Name := ' ' ;
81+ Notes := ' ' ;
82+ Compiler := ' ' ;
83+ Result := 0 ;
84+ Count := 0 ;
85+ end ;
86+
6387{ TResults }
6488
6589constructor TResults.Create(AConfigFile: String);
@@ -78,24 +102,16 @@ constructor TResults.Create(AConfigFile: String);
78102 finally
79103 configStream.Free;
80104 end ;
105+ FList := TResultsList.Create;
81106end ;
82107
83108destructor TResults.Destroy;
84109begin
85110 FConfig.Free;
111+ FList.Free;
86112 inherited Destroy;
87113end ;
88114
89- function TResults.CompareResults (const elem1, elem2): Integer;
90- var
91- i1 : TResult absolute elem1;
92- i2 : TResult absolute elem2;
93- begin
94- if i1.Result = i2.Result then Result:= 0
95- else if i1.Result < i2.Result then Result:= -1
96- else Result:= 1 ;
97- end ;
98-
99115function TResults.FormatTime (ATime: Double): String;
100116var
101117 intPart, minutes: Integer;
@@ -127,11 +143,11 @@ procedure TResults.Generate;
127143var
128144 index, index1, index2: Integer;
129145 content, hyperfineFile: String;
130- results: TResultsArray ;
146+ resultitem: TResult ;
131147 hyperfineStream: TFileStream;
132148 hyperfineJSON: TJSONData;
133149begin
134- SetLength(results, 0 ) ;
150+ FList.Clear ;
135151
136152 for index:= 0 to Pred(FConfig.Entries.Count) do
137153 begin
@@ -142,8 +158,9 @@ procedure TResults.Generate;
142158 ' -1_000_000_000-SSD.json'
143159 );
144160 if not FileExists(hyperfineFile) then continue;
145- SetLength(results, Length(results) + 1 );
146- index2:= Length(results) - 1 ;
161+ resultitem := TResult.Create;
162+ FList.Add(resultitem);
163+ index2 := FList.Count - 1 ;
147164 hyperfineStream:= TFileStream.Create(
148165 hyperfineFile,
149166 fmOpenRead
@@ -157,20 +174,20 @@ procedure TResults.Generate;
157174 try
158175 if FConfig.Entries[index].Compiler = ' fpc' then
159176 begin
160- results [index2].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
177+ FList [index2].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
161178 end ;
162179
163- results [index2].Name := FConfig.Entries[index].Name ;
164- results [index2].Notes:= FConfig.Entries[index].Notes;
165- results [index2].Result:= 0.0 ;
166- results [index2].Count:= 0 ;
180+ FList [index2].Name := FConfig.Entries[index].Name ;
181+ FList [index2].Notes:= FConfig.Entries[index].Notes;
182+ FList [index2].Result:= 0.0 ;
183+ FList [index2].Count:= 0 ;
167184 for index1:= Low(FResult.Times) to High(FResult.Times) do
168185 begin
169186 if (time = FResult.Max) or (time = FResult.Max) then continue;
170- results [index2].Result:= results [index2].Result + FResult.Times[index1];
171- Inc(results [index2].Count);
187+ FList [index2].Result:= FList [index2].Result + FResult.Times[index1];
188+ Inc(FList [index2].Count);
172189 end ;
173- results [index2].Result:= results [index2].Result / results [index2].Count;
190+ FList [index2].Result:= FList [index2].Result / FList [index2].Count;
174191 finally
175192 FResult.Free;
176193 end ;
@@ -185,17 +202,17 @@ procedure TResults.Generate;
185202 WriteLn;
186203 WriteLn;
187204
188- // AnySort(results, Length(results), SizeOf(TResult), @CompareResults);
205+ FList.Sort( @CompareResults);
189206
190207 content:= ' ' ;
191- for index:= Low(results) to High(results) do
208+ for index:= 0 to FList.Count - 1 do
192209 begin
193210 content:= content + Format(' | %d | %s | %s | %s | %s | |' +LineEnding, [
194211 index + 1 ,
195- FormatTime(results [index].Result),
196- results [index].Compiler,
197- results [index].Name ,
198- results [index].Notes
212+ FormatTime(FList [index].Result),
213+ FList [index].Compiler,
214+ FList [index].Name ,
215+ FList [index].Notes
199216 ]);
200217 end ;
201218
0 commit comments