Skip to content

Commit 92b1364

Browse files
committed
some refactorings
1 parent 92cf99a commit 92b1364

106 files changed

Lines changed: 11998 additions & 11933 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

HashLib.Benchmark/src/Core/uPerformanceBenchmark.pas

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,75 +38,76 @@ class function TPerformanceBenchmark.Calculate(const AHashInstance: IHash;
3838
const
3939
THREE_SECONDS_IN_MILLISECONDS = UInt32(3000);
4040
var
41-
MaxRate: Double;
42-
Data: TBytes;
43-
Idx: Int32;
44-
Total: Int64;
45-
A, B, TotalMilliSeconds: UInt32;
46-
NewName, BlockSizeAndUnit: String;
41+
LMaxRate: Double;
42+
LData: TBytes;
43+
LIdx: Int32;
44+
LTotal: Int64;
45+
LTickStart, LTickEnd, LTotalMilliSeconds: UInt32;
46+
LNewName, LBlockSizeAndUnit: String;
4747
begin
4848

49-
System.SetLength(Data, ASize);
49+
System.SetLength(LData, ASize);
5050

51-
for Idx := System.Low(Data) to System.High(Data) do
51+
for LIdx := System.Low(LData) to System.High(LData) do
5252
begin
53-
Data[Idx] := Byte(Random(ASize));
53+
LData[LIdx] := Byte(Random(ASize));
5454
end;
5555

56-
MaxRate := 0.0;
57-
TotalMilliSeconds := 0;
56+
LMaxRate := 0.0;
57+
LTotalMilliSeconds := 0;
5858

59-
Idx := 3;
60-
while Idx > 0 do
59+
LIdx := 3;
60+
while LIdx > 0 do
6161
begin
62-
Total := 0;
62+
LTotal := 0;
6363

64-
while (TotalMilliSeconds <= THREE_SECONDS_IN_MILLISECONDS) do
64+
while (LTotalMilliSeconds <= THREE_SECONDS_IN_MILLISECONDS) do
6565
begin
66-
A := TThread.GetTickCount;
67-
AHashInstance.ComputeBytes(Data);
68-
B := TThread.GetTickCount;
69-
Total := Total + System.Length(Data);
70-
TotalMilliSeconds := TotalMilliSeconds + (B - A);
66+
LTickStart := TThread.GetTickCount;
67+
AHashInstance.ComputeBytes(LData);
68+
LTickEnd := TThread.GetTickCount;
69+
LTotal := LTotal + System.Length(LData);
70+
LTotalMilliSeconds := LTotalMilliSeconds + (LTickEnd - LTickStart);
7171
end;
7272

73-
MaxRate := Math.Max(Total / (TotalMilliSeconds div 1000) / 1024 /
74-
1024, MaxRate);
73+
LMaxRate := Math.Max(LTotal / (LTotalMilliSeconds div 1000) / 1024 /
74+
1024, LMaxRate);
7575

76-
System.Dec(Idx);
76+
System.Dec(LIdx);
7777
end;
7878

7979
if ANamePrefix <> '' then
8080
begin
81-
NewName := Format('%s_%s', [AHashInstance.Name, ANamePrefix]);
81+
LNewName := Format('%s_%s', [AHashInstance.Name, ANamePrefix]);
8282
end
8383
else
8484
begin
85-
NewName := AHashInstance.Name;
85+
LNewName := AHashInstance.Name;
8686
end;
8787

8888
if ASize >= 1024 * 1024 * 1024 then
8989
begin
90-
BlockSizeAndUnit := Format('%d GB', [(ASize div (1024 * 1024 * 1024))]);
90+
LBlockSizeAndUnit := Format('%d GB', [(ASize div (1024 * 1024 * 1024))]);
9191
end
9292
else if ASize >= 1024 * 1024 then
9393
begin
94-
BlockSizeAndUnit := Format('%d MB', [(ASize div (1024 * 1024))]);
94+
LBlockSizeAndUnit := Format('%d MB', [(ASize div (1024 * 1024))]);
9595
end
9696
else
9797
begin
98-
BlockSizeAndUnit := Format('%d KB', [(ASize div 1024)]);
98+
LBlockSizeAndUnit := Format('%d KB', [(ASize div 1024)]);
9999
end;
100100

101101
Result := Format('%s Throughput: %.2f MB/s with Blocks of %s',
102-
[Copy(NewName, 2, System.Length(NewName) - 1), MaxRate, BlockSizeAndUnit]);
102+
[Copy(LNewName, 2, System.Length(LNewName) - 1), LMaxRate,
103+
LBlockSizeAndUnit]);
103104
end;
104105

105106
class procedure TPerformanceBenchmark.DoBenchmark(var AStringList: TStringList);
106107
begin
107108
if not Assigned(AStringList) then
108109
begin
109-
raise Exception.Create('StringList Instance cannot be Nil');
110+
raise Exception.Create('StringList Instance cannot be nil');
110111
end;
111112

112113
AStringList.Clear;
@@ -153,11 +154,11 @@ class procedure TPerformanceBenchmark.DoBenchmark(var AStringList: TStringList);
153154

154155
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake2S_256));
155156

156-
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake2BP(64, Nil)));
157+
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake2BP(64, nil)));
157158

158-
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake2SP(32, Nil)));
159+
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake2SP(32, nil)));
159160

160-
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake3_256(Nil)));
161+
AStringList.Append(Calculate(THashFactory.TCrypto.CreateBlake3_256(nil)));
161162

162163
end;
163164

0 commit comments

Comments
 (0)