bitcoin/src/bench/obfuscation.cpp
Lőrinc 377aab8e5a refactor: move util::Xor to Obfuscation().Xor
This is meant to focus the usages to narrow the scope of the obfuscation optimization.

`Obfuscation::Xor` is mostly a move.

Co-authored-by: maflcko <6399679+maflcko@users.noreply.github.com>
2025-07-16 14:33:07 -07:00

26 lines
779 B
C++

// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit/.
#include <bench/bench.h>
#include <random.h>
#include <util/obfuscation.h>
#include <cstddef>
#include <vector>
static void ObfuscationBench(benchmark::Bench& bench)
{
FastRandomContext frc{/*fDeterministic=*/true};
auto data{frc.randbytes<std::byte>(1024)};
const auto key{frc.randbytes<Obfuscation::KEY_SIZE>()};
size_t offset{0};
bench.batch(data.size()).unit("byte").run([&] {
Obfuscation().Xor(data, key, offset++); // mutated differently each time
ankerl::nanobench::doNotOptimizeAway(data);
});
}
BENCHMARK(ObfuscationBench, benchmark::PriorityLevel::HIGH);