This PR stems from the discussions in #30317 (review)
The previous benchmark for SipHash
was slightly less accurate in representing real-world usage and allowed for potential compiler optimizations that could invalidate the benchmark.
This change aims to ensure the benchmark produces more realistic results.
By modifying the initial values and only incrementing the bytes of val
, the benchmark should reflects a more typical usage patterns - and prevent the compiler from optimizing away the calculations.
On my M1 processor the benchmark’s speed changed significantly (but the CI seems to produce the same result as before):
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_BENCH=ON && cmake –build build -j10 && ./build/src/bench/bench_bitcoin –filter=SipHash_32b –min-time=1000
Before:
ns/op | op/s | err% | total | benchmark |
---|---|---|---|---|
35.15 | 28,445,856.66 | 0.2% | 1.10 | SipHash_32b |
After (note that only the benchmark changed):
ns/op | op/s | err% | total | benchmark |
---|---|---|---|---|
22.05 | 45,350,886.64 | 0.3% | 1.10 | SipHash_32b |