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#include <span.h>
10#include <util/strencodings.h>
11
12#include <vector>
13
14static void HexStrBench(benchmark::Bench& bench)
15{
16 FastRandomContext rng{/*fDeterministic=*/true};
17 auto data{rng.randbytes<std::byte>(MAX_BLOCK_WEIGHT)};
18 bench.batch(data.size()).unit("byte").run([&] {
19 auto hex = HexStr(data);
21 });
22}
23
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:632
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1288
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1312
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:1333