Bitcoin Core 31.99.0
P2P Digital Currency
strencodings.cpp
Go to the documentation of this file.
1// Copyright (c) 2022-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
7#include <crypto/hex_base.h>
8#include <random.h>
9
10#include <cstddef>
11#include <span>
12#include <string>
13#include <vector>
14
15static void HexStrBench(benchmark::Bench& bench)
16{
17 FastRandomContext rng{/*fDeterministic=*/true};
18 auto data{rng.randbytes<std::byte>(MAX_BLOCK_WEIGHT)};
19 bench.batch(data.size()).unit("byte").run([&] {
20 auto hex = HexStr(data);
22 });
23}
24
static void HexStrBench(benchmark::Bench &bench)
BENCHMARK(HexStrBench)
Fast randomness source.
Definition: random.h:386
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:649
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1308
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1332
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
Definition: consensus.h:15
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: hex_base.cpp:30
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition: nanobench.h:1353