xor.cpp raw

   1  // Copyright (c) The Limenka 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 <span.h>
   8  #include <streams.h>
   9  #include <util/obfuscation.h>
  10  
  11  #include <cstddef>
  12  #include <vector>
  13  
  14  static void Xor(benchmark::Bench& bench)
  15  {
  16      FastRandomContext frc{/*fDeterministic=*/true};
  17      auto data{frc.randbytes<std::byte>(1024)};
  18      const Obfuscation obfuscation{frc.randbytes<Obfuscation::KEY_SIZE>()};
  19  
  20      size_t offset{0};
  21      bench.batch(data.size()).unit("byte").run([&] {
  22          obfuscation(data, offset++); // mutated differently each time
  23          ankerl::nanobench::doNotOptimizeAway(data);
  24      });
  25  }
  26  
  27  BENCHMARK(Xor, benchmark::PriorityLevel::HIGH);
  28