Skip to content

Commit c122527

Browse files
fjahrsipa
andcommitted
bench: Add Muhash benchmarks
Co-authored-by: Pieter Wuille <[email protected]>
1 parent 7b12422 commit c122527

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/bench/crypto_hash.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
#include <bench/bench.h>
7+
#include <crypto/muhash.h>
78
#include <crypto/ripemd160.h>
89
#include <crypto/sha1.h>
910
#include <crypto/sha256.h>
@@ -105,6 +106,54 @@ static void FastRandom_1bit(benchmark::Bench& bench)
105106
});
106107
}
107108

109+
static void MuHash(benchmark::Bench& bench)
110+
{
111+
MuHash3072 acc;
112+
unsigned char key[32] = {0};
113+
int i = 0;
114+
bench.run([&] {
115+
key[0] = ++i;
116+
acc *= MuHash3072(key);
117+
});
118+
}
119+
120+
static void MuHashMul(benchmark::Bench& bench)
121+
{
122+
MuHash3072 acc;
123+
FastRandomContext rng(true);
124+
MuHash3072 muhash{rng.randbytes(32)};
125+
126+
bench.run([&] {
127+
acc *= muhash;
128+
});
129+
}
130+
131+
static void MuHashDiv(benchmark::Bench& bench)
132+
{
133+
MuHash3072 acc;
134+
FastRandomContext rng(true);
135+
MuHash3072 muhash{rng.randbytes(32)};
136+
137+
for (size_t i = 0; i < bench.epochIterations(); ++i) {
138+
acc *= muhash;
139+
}
140+
141+
bench.run([&] {
142+
acc /= muhash;
143+
});
144+
}
145+
146+
static void MuHashPrecompute(benchmark::Bench& bench)
147+
{
148+
MuHash3072 acc;
149+
FastRandomContext rng(true);
150+
std::vector<unsigned char> key{rng.randbytes(32)};
151+
152+
bench.run([&] {
153+
MuHash3072{key};
154+
});
155+
}
156+
108157
BENCHMARK(RIPEMD160);
109158
BENCHMARK(SHA1);
110159
BENCHMARK(SHA256);
@@ -116,3 +165,8 @@ BENCHMARK(SipHash_32b);
116165
BENCHMARK(SHA256D64_1024);
117166
BENCHMARK(FastRandom_32bit);
118167
BENCHMARK(FastRandom_1bit);
168+
169+
BENCHMARK(MuHash);
170+
BENCHMARK(MuHashMul);
171+
BENCHMARK(MuHashDiv);
172+
BENCHMARK(MuHashPrecompute);

0 commit comments

Comments
 (0)