Skip to content

Commit 7aab38c

Browse files
authored
Merge pull request #52 from paweld/gus
changes in results analysis
2 parents d25cdb4 + 497c127 commit 7aab38c

File tree

2 files changed

+83
-49
lines changed

2 files changed

+83
-49
lines changed

utilities/common/utilities.data.hyperfine.pas

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,29 @@ interface
88
Classes
99
, SysUtils
1010
, fpjson
11+
, fpjsonrtti
12+
, fgl
1113
;
1214

1315
const
1416
cJSONHyperfineResult = 'results[0]';
1517

1618
type
19+
20+
{ TDoubleList }
21+
22+
TDoubleList = class(specialize TFPGList<Double>)
23+
public
24+
function AvgValue: Double;
25+
function AvgValueWithOutMinMax: Double;
26+
end;
27+
28+
TIntegerList = specialize TFPGList<Integer>;
29+
1730
{ EResultNotAJSONObject }
1831
EResultNotAJSONObject = Exception;
1932

2033
{ THyperfineResult }
21-
TArrayOfTime = array of Double;
2234
THyperfineResult = class(TObject)
2335
private
2436
FCommand: String;
@@ -29,7 +41,8 @@ THyperfineResult = class(TObject)
2941
FSystem: Double;
3042
FMin: Double;
3143
FMax: Double;
32-
FTimes: TArrayOfTime;
44+
FTimes: TDoubleList;
45+
FExitCodes: TIntegerList;
3346

3447
procedure setFromJSONData(const AJSONData: TJSONData);
3548
procedure setFromJSONObject(const AJSONObject: TJSONObject);
@@ -39,53 +52,87 @@ THyperfineResult = class(TObject)
3952
constructor Create(const AJSONData: TJSONData);
4053

4154
destructor Destroy; override;
42-
43-
property Command: String
55+
published
56+
property command: String
4457
read FCommand
4558
write FCommand;
46-
property Mean: Double
59+
property mean: Double
4760
read fMean
4861
write FMean;
49-
property StandardDeviation: Double
62+
property stddev: Double
5063
read FStandardDeviation
5164
write FStandardDeviation;
52-
property Median: Double
65+
property median: Double
5366
read FMedian
5467
write FMedian;
55-
property User: Double
68+
property user: Double
5669
read FUser
5770
write FUser;
58-
property System: Double
71+
property system: Double
5972
read FSystem
6073
write FSystem;
61-
property Min: Double
74+
property min: Double
6275
read FMin
6376
write FMin;
64-
property Max: Double
77+
property max: Double
6578
read FMax
6679
write FMax;
67-
property Times: TArrayOfTime
80+
property times: TDoubleList
6881
read FTimes
6982
write FTimes;
70-
published
83+
property exit_codes: TIntegerList
84+
read FExitCodes
85+
write FExitCodes;
7186
end;
7287

7388
implementation
7489

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-
8690
resourcestring
8791
rsExceptionNotAJSONObject = 'JSON Data is not an object';
8892

93+
function CompareDouble(const d1, d2: Double): Integer;
94+
begin
95+
if d1 = d2 then Result:= 0
96+
else if d1 < d2 then Result:= -1
97+
else Result:= 1;
98+
end;
99+
100+
{ TDoubleList }
101+
102+
function TDoubleList.AvgValue: Double;
103+
var
104+
i: Integer;
105+
sum: Double;
106+
begin
107+
Result := 0;
108+
if Count = 0 then
109+
exit;
110+
sum := 0;
111+
for i := 0 to Count - 1 do
112+
sum := sum + Items[i];
113+
Result := sum / Count;
114+
end;
115+
116+
function TDoubleList.AvgValueWithOutMinMax: Double;
117+
var
118+
sortedlist: TDoubleList;
119+
i: Integer;
120+
sum: Double;
121+
begin
122+
Result := 0;
123+
if Count <= 2 then
124+
exit;
125+
sum := 0;
126+
sortedlist := TDoubleList.Create;
127+
for i := 0 to Count - 1 do
128+
sortedlist.Add(Items[i]);
129+
sortedlist.Sort(@CompareDouble);
130+
for i := 1 to sortedlist.Count - 2 do
131+
sum := sum + sortedlist[i];
132+
Result := sum / (sortedlist.Count - 2);
133+
sortedlist.Free;
134+
end;
135+
89136
{ THyperfineResult }
90137

91138
constructor THyperfineResult.Create;
@@ -98,7 +145,8 @@ constructor THyperfineResult.Create;
98145
FSystem:= 0.0;
99146
FMin:= 0.0;
100147
FMax:= 0.0;
101-
SetLength(FTimes, 0);
148+
FTimes := TDoubleList.Create;
149+
FExitCodes := TIntegerList.Create;
102150
end;
103151

104152
constructor THyperfineResult.Create(const AJSONData: TJSONData);
@@ -109,6 +157,8 @@ constructor THyperfineResult.Create(const AJSONData: TJSONData);
109157

110158
destructor THyperfineResult.Destroy;
111159
begin
160+
FTimes.Free;
161+
FExitCodes.Free;
112162
inherited Destroy;
113163
end;
114164

@@ -123,22 +173,13 @@ procedure THyperfineResult.setFromJSONData(const AJSONData: TJSONData);
123173

124174
procedure THyperfineResult.setFromJSONObject(const AJSONObject: TJSONObject);
125175
var
126-
timesObject: TJSONArray;
127-
index: Integer;
176+
jds: TJSONDestreamer;
128177
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;
178+
jds := TJSONDestreamer.Create(nil);
179+
try
180+
jds.JSONToObject(AJSONObject.AsJSON, Self);
181+
finally
182+
jds.Free;
142183
end;
143184
end;
144185

utilities/results_generator/Common/resultsgenerator.common.pas

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,8 @@ procedure TResults.Generate;
176176

177177
FList[index2].Name:= FConfig.Entries[index].Name;
178178
FList[index2].Notes:= FConfig.Entries[index].Notes;
179-
FList[index2].Result:= 0.0;
180-
FList[index2].Count:= 0;
181-
for index1:= Low(FResult.Times) to High(FResult.Times) do
182-
begin
183-
if (time = FResult.Max) or (time = FResult.Max) then continue;
184-
FList[index2].Result:= FList[index2].Result + FResult.Times[index1];
185-
Inc(FList[index2].Count);
186-
end;
187-
FList[index2].Result:= FList[index2].Result / FList[index2].Count;
179+
FList[index2].Count := FResult.times.Count;
180+
FList[index2].Result:= FResult.times.AvgValueWithOutMinMax;
188181
finally
189182
FResult.Free;
190183
end;

0 commit comments

Comments
 (0)