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 |
---|---|---|---|---|
43.90 | 22,780,157.00 | 0.1% | 1.09 | SipHash_32b |
43.92 | 22,768,946.21 | 0.0% | 1.09 | SipHash_32b |
43.91 | 22,775,604.29 | 0.1% | 1.09 | SipHash_32b |
After (note, the hash didn’t change, only the benchmark did):
ns/op | op/s | err% | total | benchmark |
---|---|---|---|---|
27.63 | 36,193,173.27 | 0.1% | 1.09 | SipHash_32b |
27.61 | 36,220,514.83 | 0.1% | 1.09 | SipHash_32b |
27.64 | 36,180,519.38 | 0.1% | 1.09 | SipHash_32b |