obfuscation.cpp raw

   1  // Copyright (c) The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or https://opensource.org/license/mit/.
   4  
   5  #include <bench/bench.h>
   6  #include <random.h>
   7  #include <util/obfuscation.h>
   8  
   9  #include <cstddef>
  10  #include <span>
  11  #include <vector>
  12  
  13  static void ObfuscationBench(benchmark::Bench& bench)
  14  {
  15      FastRandomContext frc{/*fDeterministic=*/true};
  16      auto data{frc.randbytes<std::byte>(1024)};
  17      const Obfuscation obfuscation{frc.randbytes<Obfuscation::KEY_SIZE>()};
  18  
  19      size_t offset{0};
  20      bench.batch(data.size()).unit("byte").run([&] {
  21          obfuscation(data, offset++); // mutated differently each time
  22          ankerl::nanobench::doNotOptimizeAway(data);
  23      });
  24  }
  25  
  26  BENCHMARK(ObfuscationBench);
  27