@@ -9,20 +9,36 @@ interface
9
9
uses
10
10
Classes
11
11
, SysUtils
12
+ , fgl
12
13
, Utilities.Data.Config
13
14
, Utilities.Data.Entries
14
15
, Utilities.Data.Hyperfine
15
16
;
16
17
17
18
type
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
+
19
35
TResults = class (TObject)
20
36
private
21
37
FConfig: TConfig;
22
38
FResult: THyperfineResult;
39
+ FList: TResultsList;
23
40
24
41
function GenerateProgressBar (APBPosition, APBMax, APBWIdth: Integer): String;
25
- function CompareResults (const elem1, elem2): Integer;
26
42
function FormatTime (ATime: Double): String;
27
43
protected
28
44
public
@@ -42,24 +58,32 @@ implementation
42
58
, Utilities.ArraySort
43
59
;
44
60
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
-
56
61
const
57
62
lineBreak = #13 ;
58
63
59
64
cTableHeader =
60
65
' | # | Result (m:s.ms): SSD | Compiler | Submitter | Notes | Certificates |' #10 +
61
66
' |--:|---------------------:|:---------|:--------------|:----------|:-------------|' #10 ;
62
67
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
+
63
87
{ TResults }
64
88
65
89
constructor TResults.Create(AConfigFile: String);
@@ -78,24 +102,16 @@ constructor TResults.Create(AConfigFile: String);
78
102
finally
79
103
configStream.Free;
80
104
end ;
105
+ FList := TResultsList.Create;
81
106
end ;
82
107
83
108
destructor TResults.Destroy;
84
109
begin
85
110
FConfig.Free;
111
+ FList.Free;
86
112
inherited Destroy;
87
113
end ;
88
114
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
-
99
115
function TResults.FormatTime (ATime: Double): String;
100
116
var
101
117
intPart, minutes: Integer;
@@ -127,11 +143,11 @@ procedure TResults.Generate;
127
143
var
128
144
index, index1, index2: Integer;
129
145
content, hyperfineFile: String;
130
- results: TResultsArray ;
146
+ resultitem: TResult ;
131
147
hyperfineStream: TFileStream;
132
148
hyperfineJSON: TJSONData;
133
149
begin
134
- SetLength(results, 0 ) ;
150
+ FList.Clear ;
135
151
136
152
for index:= 0 to Pred(FConfig.Entries.Count) do
137
153
begin
@@ -142,8 +158,9 @@ procedure TResults.Generate;
142
158
' -1_000_000_000-SSD.json'
143
159
);
144
160
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 ;
147
164
hyperfineStream:= TFileStream.Create(
148
165
hyperfineFile,
149
166
fmOpenRead
@@ -157,20 +174,20 @@ procedure TResults.Generate;
157
174
try
158
175
if FConfig.Entries[index].Compiler = ' fpc' then
159
176
begin
160
- results [index2].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
177
+ FList [index2].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
161
178
end ;
162
179
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 ;
167
184
for index1:= Low(FResult.Times) to High(FResult.Times) do
168
185
begin
169
186
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);
172
189
end ;
173
- results [index2].Result:= results [index2].Result / results [index2].Count;
190
+ FList [index2].Result:= FList [index2].Result / FList [index2].Count;
174
191
finally
175
192
FResult.Free;
176
193
end ;
@@ -185,17 +202,17 @@ procedure TResults.Generate;
185
202
WriteLn;
186
203
WriteLn;
187
204
188
- // AnySort(results, Length(results), SizeOf(TResult), @CompareResults);
205
+ FList.Sort( @CompareResults);
189
206
190
207
content:= ' ' ;
191
- for index:= Low(results) to High(results) do
208
+ for index:= 0 to FList.Count - 1 do
192
209
begin
193
210
content:= content + Format(' | %d | %s | %s | %s | %s | |' +LineEnding, [
194
211
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
199
216
]);
200
217
end ;
201
218
0 commit comments