bench: make XorObfuscationBench more representative

Since a previous PR already solved the tiny byte-array xors during serialization, we're only concentrating on big continuous chunks now.

>  cmake -B build -DBUILD_BENCH=ON -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build -j$(nproc) \
&& build/bin/bench_bitcoin -filter='XorObfuscationBench' -min-time=10000

C++ compiler .......................... AppleClang 17.0.0.17000013

|              ns/MiB |               MiB/s |    err% |     total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
|          731,927.62 |            1,366.26 |    0.2% |     10.67 | `XorObfuscationBench`

C++ compiler .......................... GNU 13.3.0

|              ns/MiB |               MiB/s |    err% |         ins/MiB |         cyc/MiB |    IPC |        bra/MiB |   miss% |     total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|          941,015.26 |            1,062.68 |    0.0% |    9,437,186.97 |    3,378,911.52 |  2.793 |   1,048,577.15 |    0.0% |     10.99 | `XorObfuscationBench`
This commit is contained in:
Lőrinc 2024-12-06 16:18:03 +01:00
parent b9c54ccd8c
commit 366bffd125

View file

@ -6,19 +6,24 @@
#include <random.h> #include <random.h>
#include <span.h> #include <span.h>
#include <streams.h> #include <streams.h>
#include <util/byte_units.h>
#include <cstddef> #include <cstddef>
#include <vector> #include <vector>
static void Xor(benchmark::Bench& bench) static void XorObfuscationBench(benchmark::Bench& bench)
{ {
FastRandomContext frc{/*fDeterministic=*/true}; FastRandomContext rng{/*fDeterministic=*/true};
auto data{frc.randbytes<std::byte>(1024)}; constexpr size_t bytes{10_MiB};
auto key{frc.randbytes<std::byte>(31)}; auto test_data{rng.randbytes<std::byte>(bytes)};
bench.batch(data.size()).unit("byte").run([&] { const std::vector obfuscation{rng.randbytes<std::byte>(8)};
util::Xor(data, key);
size_t offset{0};
bench.batch(bytes / 1_MiB).unit("MiB").run([&] {
util::Xor(test_data, obfuscation, offset++);
ankerl::nanobench::doNotOptimizeAway(test_data);
}); });
} }
BENCHMARK(Xor, benchmark::PriorityLevel::HIGH); BENCHMARK(XorObfuscationBench, benchmark::PriorityLevel::HIGH);