bench: add fixed-width SipHash benchmarks
What changed, and why it matters
This commit only adds new performance benchmark tests for a hash function called SipHash. It does not change any production code that handles Bitcoin transactions, networking, or wallet data. There is no security issue here.
No action needed. This is a benign benchmark-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies src/bench/crypto_hash.cpp, a benchmarking file. It renames an existing SipHash benchmark and adds three new benchmark functions (SipHash24_36b, SipHash13UJ_32b, SipHash13UJ_36b) using existing SipHasher classes. No cryptographic, consensus, or runtime logic is changed. The commit message explicitly frames this as preparatory benchmark work before changing CCoinsMap’s hasher.
Changed components
src/bench/crypto_hash.cppInspect captured patch +49 / −3
diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp
index 4d0660db..82744897 100644
--- a/src/bench/crypto_hash.cpp
+++ b/src/bench/crypto_hash.cpp
@@ -190,10 +190,10 @@ static void SHA512(benchmark::Bench& bench)
});
}
-static void SipHash_32b(benchmark::Bench& bench)
+static void SipHash24_32b(benchmark::Bench& bench)
{
FastRandomContext rng{/*fDeterministic=*/true};
- PresaltedSipHasher presalted_sip_hasher(rng.rand64(), rng.rand64());
+ PresaltedSipHasher presalted_sip_hasher{rng.rand64(), rng.rand64()};
auto val{rng.rand256()};
auto i{0U};
bench.run([&] {
@@ -203,6 +203,49 @@ static void SipHash_32b(benchmark::Bench& bench)
});
}
+static void SipHash24_36b(benchmark::Bench& bench)
+{
+ FastRandomContext rng{/*fDeterministic=*/true};
+ PresaltedSipHasher presalted_sip_hasher{rng.rand64(), rng.rand64()};
+ auto val{rng.rand256()};
+ uint32_t extra{rng.rand32()};
+ auto i{0U};
+ bench.run([&] {
+ ankerl::nanobench::doNotOptimizeAway(presalted_sip_hasher(val, extra));
+ ++i;
+ val.data()[i % uint256::size()] ^= i & 0xFF;
+ extra += i;
+ });
+}
+
+static void SipHash13UJ_32b(benchmark::Bench& bench)
+{
+ FastRandomContext rng{/*fDeterministic=*/true};
+ SipHasher13UJ sip_hasher{rng.rand64(), rng.rand64()};
+ auto val{rng.rand256()};
+ auto i{0U};
+ bench.run([&] {
+ ankerl::nanobench::doNotOptimizeAway(sip_hasher.Hash(val));
+ ++i;
+ val.data()[i % uint256::size()] ^= i & 0xFF;
+ });
+}
+
+static void SipHash13UJ_36b(benchmark::Bench& bench)
+{
+ FastRandomContext rng{/*fDeterministic=*/true};
+ SipHasher13UJ sip_hasher{rng.rand64(), rng.rand64()};
+ auto val{rng.rand256()};
+ uint32_t extra{rng.rand32()};
+ auto i{0U};
+ bench.run([&] {
+ ankerl::nanobench::doNotOptimizeAway(sip_hasher.Hash(val, uint64_t{extra}));
+ ++i;
+ val.data()[i % uint256::size()] ^= i & 0xFF;
+ extra += i;
+ });
+}
+
static void MuHash(benchmark::Bench& bench)
{
MuHash3072 acc;
@@ -273,7 +316,10 @@ BENCHMARK(SHA256_32b_STANDARD);
BENCHMARK(SHA256_32b_SSE4);
BENCHMARK(SHA256_32b_AVX2);
BENCHMARK(SHA256_32b_SHANI);
-BENCHMARK(SipHash_32b);
+BENCHMARK(SipHash24_32b);
+BENCHMARK(SipHash24_36b);
+BENCHMARK(SipHash13UJ_32b);
+BENCHMARK(SipHash13UJ_36b);
BENCHMARK(SHA256D64_1024_STANDARD);
BENCHMARK(SHA256D64_1024_SSE4);
BENCHMARK(SHA256D64_1024_AVX2);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.