Skip to content

Commit e9a45e9

Browse files
UdjinM6CryptoCentric
authored andcommitted
Add DSHA256 and X11 benchmarks, refactor names of other algo benchmarks to group them together (dashpay#1925)
DSHA256 and X11 also have additional tests for data from 32 to 2048 bytes (for comparison, in steps)
1 parent d5af519 commit e9a45e9

File tree

1 file changed

+145
-12
lines changed

1 file changed

+145
-12
lines changed

src/bench/crypto_hash.cpp

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2016 The Bitcoin Core developers
2+
// Copyright (c) 2018 The Dash Core developers
23
// Distributed under the MIT software license, see the accompanying
34
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
45

@@ -18,31 +19,31 @@
1819
/* Number of bytes to hash per iteration */
1920
static const uint64_t BUFFER_SIZE = 1000*1000;
2021

21-
static void RIPEMD160(benchmark::State& state)
22+
static void HASH_RIPEMD160(benchmark::State& state)
2223
{
2324
uint8_t hash[CRIPEMD160::OUTPUT_SIZE];
2425
std::vector<uint8_t> in(BUFFER_SIZE,0);
2526
while (state.KeepRunning())
2627
CRIPEMD160().Write(in.data(), in.size()).Finalize(hash);
2728
}
2829

29-
static void SHA1(benchmark::State& state)
30+
static void HASH_SHA1(benchmark::State& state)
3031
{
3132
uint8_t hash[CSHA1::OUTPUT_SIZE];
3233
std::vector<uint8_t> in(BUFFER_SIZE,0);
3334
while (state.KeepRunning())
3435
CSHA1().Write(in.data(), in.size()).Finalize(hash);
3536
}
3637

37-
static void SHA256(benchmark::State& state)
38+
static void HASH_SHA256(benchmark::State& state)
3839
{
3940
uint8_t hash[CSHA256::OUTPUT_SIZE];
4041
std::vector<uint8_t> in(BUFFER_SIZE,0);
4142
while (state.KeepRunning())
4243
CSHA256().Write(in.data(), in.size()).Finalize(hash);
4344
}
4445

45-
static void SHA256_32b(benchmark::State& state)
46+
static void HASH_SHA256_0032b(benchmark::State& state)
4647
{
4748
std::vector<uint8_t> in(32,0);
4849
while (state.KeepRunning()) {
@@ -52,15 +53,33 @@ static void SHA256_32b(benchmark::State& state)
5253
}
5354
}
5455

55-
static void SHA512(benchmark::State& state)
56+
static void HASH_DSHA256(benchmark::State& state)
57+
{
58+
uint8_t hash[CSHA256::OUTPUT_SIZE];
59+
std::vector<uint8_t> in(BUFFER_SIZE,0);
60+
while (state.KeepRunning())
61+
CHash256().Write(in.data(), in.size()).Finalize(hash);
62+
}
63+
64+
static void HASH_DSHA256_0032b(benchmark::State& state)
65+
{
66+
std::vector<uint8_t> in(32,0);
67+
while (state.KeepRunning()) {
68+
for (int i = 0; i < 1000000; i++) {
69+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
70+
}
71+
}
72+
}
73+
74+
static void HASH_SHA512(benchmark::State& state)
5675
{
5776
uint8_t hash[CSHA512::OUTPUT_SIZE];
5877
std::vector<uint8_t> in(BUFFER_SIZE,0);
5978
while (state.KeepRunning())
6079
CSHA512().Write(in.data(), in.size()).Finalize(hash);
6180
}
6281

63-
static void SipHash_32b(benchmark::State& state)
82+
static void HASH_SipHash_0032b(benchmark::State& state)
6483
{
6584
uint256 x;
6685
while (state.KeepRunning()) {
@@ -70,10 +89,124 @@ static void SipHash_32b(benchmark::State& state)
7089
}
7190
}
7291

73-
BENCHMARK(RIPEMD160);
74-
BENCHMARK(SHA1);
75-
BENCHMARK(SHA256);
76-
BENCHMARK(SHA512);
92+
static void HASH_DSHA256_0032b_single(benchmark::State& state)
93+
{
94+
std::vector<uint8_t> in(32,0);
95+
while (state.KeepRunning())
96+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
97+
}
98+
99+
static void HASH_DSHA256_0080b_single(benchmark::State& state)
100+
{
101+
std::vector<uint8_t> in(80,0);
102+
while (state.KeepRunning())
103+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
104+
}
105+
106+
static void HASH_DSHA256_0128b_single(benchmark::State& state)
107+
{
108+
std::vector<uint8_t> in(128,0);
109+
while (state.KeepRunning())
110+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
111+
}
112+
113+
static void HASH_DSHA256_0512b_single(benchmark::State& state)
114+
{
115+
std::vector<uint8_t> in(512,0);
116+
while (state.KeepRunning())
117+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
118+
}
119+
120+
static void HASH_DSHA256_1024b_single(benchmark::State& state)
121+
{
122+
std::vector<uint8_t> in(1024,0);
123+
while (state.KeepRunning())
124+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
125+
}
126+
127+
static void HASH_DSHA256_2048b_single(benchmark::State& state)
128+
{
129+
std::vector<uint8_t> in(2048,0);
130+
while (state.KeepRunning())
131+
CHash256().Write(in.data(), in.size()).Finalize(&in[0]);
132+
}
133+
134+
static void HASH_X11(benchmark::State& state)
135+
{
136+
uint256 hash;
137+
std::vector<uint8_t> in(BUFFER_SIZE,0);
138+
while (state.KeepRunning())
139+
hash = HashX11(in.begin(), in.end());
140+
}
141+
142+
static void HASH_X11_0032b_single(benchmark::State& state)
143+
{
144+
uint256 hash;
145+
std::vector<uint8_t> in(32,0);
146+
while (state.KeepRunning())
147+
hash = HashX11(in.begin(), in.end());
148+
}
149+
150+
static void HASH_X11_0080b_single(benchmark::State& state)
151+
{
152+
uint256 hash;
153+
std::vector<uint8_t> in(80,0);
154+
while (state.KeepRunning())
155+
hash = HashX11(in.begin(), in.end());
156+
}
157+
158+
static void HASH_X11_0128b_single(benchmark::State& state)
159+
{
160+
uint256 hash;
161+
std::vector<uint8_t> in(128,0);
162+
while (state.KeepRunning())
163+
hash = HashX11(in.begin(), in.end());
164+
}
165+
166+
static void HASH_X11_0512b_single(benchmark::State& state)
167+
{
168+
uint256 hash;
169+
std::vector<uint8_t> in(512,0);
170+
while (state.KeepRunning())
171+
hash = HashX11(in.begin(), in.end());
172+
}
173+
174+
static void HASH_X11_1024b_single(benchmark::State& state)
175+
{
176+
uint256 hash;
177+
std::vector<uint8_t> in(1024,0);
178+
while (state.KeepRunning())
179+
hash = HashX11(in.begin(), in.end());
180+
}
181+
182+
static void HASH_X11_2048b_single(benchmark::State& state)
183+
{
184+
uint256 hash;
185+
std::vector<uint8_t> in(2048,0);
186+
while (state.KeepRunning())
187+
hash = HashX11(in.begin(), in.end());
188+
}
189+
190+
BENCHMARK(HASH_RIPEMD160);
191+
BENCHMARK(HASH_SHA1);
192+
BENCHMARK(HASH_SHA256);
193+
BENCHMARK(HASH_DSHA256);
194+
BENCHMARK(HASH_SHA512);
195+
BENCHMARK(HASH_X11);
196+
197+
BENCHMARK(HASH_SHA256_0032b);
198+
BENCHMARK(HASH_DSHA256_0032b);
199+
BENCHMARK(HASH_SipHash_0032b);
77200

78-
BENCHMARK(SHA256_32b);
79-
BENCHMARK(SipHash_32b);
201+
BENCHMARK(HASH_DSHA256_0032b_single);
202+
BENCHMARK(HASH_DSHA256_0080b_single);
203+
BENCHMARK(HASH_DSHA256_0128b_single);
204+
BENCHMARK(HASH_DSHA256_0512b_single);
205+
BENCHMARK(HASH_DSHA256_1024b_single);
206+
BENCHMARK(HASH_DSHA256_2048b_single);
207+
BENCHMARK(HASH_X11_0032b_single);
208+
BENCHMARK(HASH_X11_0080b_single);
209+
BENCHMARK(HASH_X11_0128b_single);
210+
BENCHMARK(HASH_X11_0512b_single);
211+
BENCHMARK(HASH_X11_1024b_single);
212+
BENCHMARK(HASH_X11_2048b_single);

0 commit comments

Comments
 (0)