/ src / bench / strencodings.cpp
strencodings.cpp
 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>
 6  #include <consensus/consensus.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  
14  static 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);
20          ankerl::nanobench::doNotOptimizeAway(hex);
21      });
22  }
23  
24  BENCHMARK(HexStrBench);