Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
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
#define BENCHMARK(n)
Definition bench.h:69
static void HexStrBench(benchmark::Bench &bench)
Fast randomness source.
Definition random.h:386
std::vector< B > randbytes(size_t len) noexcept
Generate random bytes.
Definition random.h:297
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
Bench & unit(char const *unit)
Sets the operation unit.
constexpr 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
FastRandomContext rng