Files
bitcoin/src/bench/strencodings.cpp
Lőrinc 353c660be5 bench: use deterministic HexStr payload
`HexStrBench` uses the bytes from the embedded block fixture as a random source of bytes to measure `HexStr` performance against.
This coupling makes block benchmark migrations slightly more work than necessary.

We can use deterministic pseudo-random bytes instead so this benchmark keeps stable input without fixture coupling.
Use `MAX_BLOCK_WEIGHT` so the benchmark stays in the same size range and keeps measured work above harness overhead.
This changes the benchmark baseline because input size moves from about 1 MB to 4 MB.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2026-02-16 14:02:18 +01:00

24 lines
678 B
C++

// Copyright (c) 2022-present 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 <bench/bench.h>
#include <consensus/consensus.h>
#include <random.h>
#include <span.h>
#include <util/strencodings.h>
#include <vector>
static void HexStrBench(benchmark::Bench& bench)
{
FastRandomContext rng{/*fDeterministic=*/true};
auto data{rng.randbytes<std::byte>(MAX_BLOCK_WEIGHT)};
bench.batch(data.size()).unit("byte").run([&] {
auto hex = HexStr(data);
ankerl::nanobench::doNotOptimizeAway(hex);
});
}
BENCHMARK(HexStrBench);