strencodings.cpp raw

   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  
  10  #include <cstddef>
  11  #include <span>
  12  #include <string>
  13  #include <vector>
  14  
  15  static 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);
  21          ankerl::nanobench::doNotOptimizeAway(hex);
  22      });
  23  }
  24  
  25  BENCHMARK(HexStrBench);
  26