mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 05:32:22 +02:00
bench: add fixed-width SipHash benchmarks
Benchmark 32-byte hashes and inputs consisting of a 32-byte hash plus a 32-bit index with SipHash-2-4 and SipHash-1-3-UJ. The UJ benchmark zero-extends the index into one 64-bit normal block. Keep all four measurements together after shared correctness coverage and before changing `CCoinsMap`'s hasher. Co-authored-by: Pieter Wuille <pieter@wuille.net>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user