From 0a9bbc64c157a314e5472ecd98300e30b12d3fdf Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 5 Jul 2024 09:51:26 -0400 Subject: [PATCH] random bench refactor: move to new bench/random.cpp --- src/Makefile.bench.include | 1 + src/bench/crypto_hash.cpp | 18 ------------------ src/bench/random.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 src/bench/random.cpp diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index 2ba72c9e76b..cd2626b3307 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -49,6 +49,7 @@ bench_bench_bitcoin_SOURCES = \ bench/poly1305.cpp \ bench/pool.cpp \ bench/prevector.cpp \ + bench/random.cpp \ bench/readblock.cpp \ bench/rollingbloom.cpp \ bench/rpc_blockchain.cpp \ diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 1685a120b45..2551ff35936 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -196,22 +196,6 @@ static void SipHash_32b(benchmark::Bench& bench) }); } -static void FastRandom_32bit(benchmark::Bench& bench) -{ - FastRandomContext rng(true); - bench.run([&] { - rng.rand32(); - }); -} - -static void FastRandom_1bit(benchmark::Bench& bench) -{ - FastRandomContext rng(true); - bench.run([&] { - rng.randbool(); - }); -} - static void MuHash(benchmark::Bench& bench) { MuHash3072 acc; @@ -274,8 +258,6 @@ BENCHMARK(SHA256D64_1024_STANDARD, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA256D64_1024_SSE4, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA256D64_1024_AVX2, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA256D64_1024_SHANI, benchmark::PriorityLevel::HIGH); -BENCHMARK(FastRandom_32bit, benchmark::PriorityLevel::HIGH); -BENCHMARK(FastRandom_1bit, benchmark::PriorityLevel::HIGH); BENCHMARK(MuHash, benchmark::PriorityLevel::HIGH); BENCHMARK(MuHashMul, benchmark::PriorityLevel::HIGH); diff --git a/src/bench/random.cpp b/src/bench/random.cpp new file mode 100644 index 00000000000..124fb3d2c20 --- /dev/null +++ b/src/bench/random.cpp @@ -0,0 +1,25 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +static void FastRandom_32bit(benchmark::Bench& bench) +{ + FastRandomContext rng(true); + bench.run([&] { + rng.rand32(); + }); +} + +static void FastRandom_1bit(benchmark::Bench& bench) +{ + FastRandomContext rng(true); + bench.run([&] { + rng.randbool(); + }); +} + +BENCHMARK(FastRandom_32bit, benchmark::PriorityLevel::HIGH); +BENCHMARK(FastRandom_1bit, benchmark::PriorityLevel::HIGH);