@@ -22,6 +22,8 @@ TResults = class(TObject)
2222 FResult: THyperfineResult;
2323
2424 function GenerateProgressBar (APBPosition, APBMax, APBWIdth: Integer): String;
25+ function CompareResults (const elem1, elem2): Integer;
26+ function FormatTime (ATime: Double): String;
2527 protected
2628 public
2729 constructor Create(AConfigFile: String);
@@ -36,8 +38,21 @@ implementation
3638uses
3739 fpjson
3840, jsonparser
41+ , Math
42+ , Utilities.ArraySort
3943;
4044
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+
4156const
4257 lineBreak = #13 ;
4358
@@ -71,24 +86,52 @@ destructor TResults.Destroy;
7186 inherited Destroy;
7287end ;
7388
74- procedure TResults.Generate ;
75- type
76- TResult = record
77- Result: Double;
78- Count: Integer;
79- Compiler: String;
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+ function TResults.FormatTime (ATime: Double): String;
100+ var
101+ intPart, minutes: Integer;
102+ millis: String;
103+ begin
104+ Result:= ' ' ;
105+ intPart:= Trunc(ATime);
106+ minutes:= 0 ;
107+ if intPart > 60 then
108+ begin
109+ repeat
110+ Inc(minutes);
111+ Dec(intPart, 60 );
112+ until intPart < 60 ;
80113 end ;
81- TResultsArray = array of TResult;
114+ millis:= Copy(
115+ FloatToStr(ATime),
116+ Pos(' .' , FloatToStr(ATime)) + 1 ,
117+ 4
118+ );
119+ Result:= Format(' %d:%d.%s' ,[
120+ minutes,
121+ intPart,
122+ millis
123+ ]);
124+ end ;
82125
126+ procedure TResults.Generate ;
83127var
84- index, index1: Integer;
128+ index, index1, index2 : Integer;
85129 content, hyperfineFile: String;
86130 results: TResultsArray;
87131 hyperfineStream: TFileStream;
88132 hyperfineJSON: TJSONData;
89133begin
90- content:= ' ' ;
91- SetLength(results, FConfig.Entries.Count);
134+ SetLength(results, 0 );
92135
93136 for index:= 0 to Pred(FConfig.Entries.Count) do
94137 begin
@@ -99,6 +142,8 @@ TResult = record
99142 ' -1_000_000_000-SSD.json'
100143 );
101144 if not FileExists(hyperfineFile) then continue;
145+ SetLength(results, Length(results) + 1 );
146+ index2:= Length(results) - 1 ;
102147 hyperfineStream:= TFileStream.Create(
103148 hyperfineFile,
104149 fmOpenRead
@@ -112,26 +157,20 @@ TResult = record
112157 try
113158 if FConfig.Entries[index].Compiler = ' fpc' then
114159 begin
115- results[index ].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
160+ results[index2 ].Compiler:= ' lazarus-3.0, fpc-3.2.2' ;
116161 end ;
117162
118- results[index].Result:= 0.0 ;
119- results[index].Count:= 0 ;
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 ;
120167 for index1:= Low(FResult.Times) to High(FResult.Times) do
121168 begin
122169 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);
170+ results[index2 ].Result:= results[index2 ].Result + FResult.Times[index1];
171+ Inc(results[index2 ].Count);
125172 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- ]);
173+ results[index2].Result:= results[index2].Result / results[index2].Count;
135174 finally
136175 FResult.Free;
137176 end ;
@@ -145,8 +184,22 @@ TResult = record
145184
146185 WriteLn;
147186 WriteLn;
187+
188+ // AnySort(results, Length(results), SizeOf(TResult), @CompareResults);
189+
190+ content:= ' ' ;
191+ for index:= Low(results) to High(results) do
192+ begin
193+ content:= content + Format(' | %d | %s | %s | %s | %s | |' +LineEnding, [
194+ index + 1 ,
195+ FormatTime(results[index].Result),
196+ results[index].Compiler,
197+ results[index].Name ,
198+ results[index].Notes
199+ ]);
200+ end ;
201+
148202 Write(cTableHeader, content);
149- // The results
150203 WriteLn;
151204end ;
152205
0 commit comments