bench: Make XorObfuscationBench more representative

Since another PR solves the tiny byte 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 3d203c2acf
commit 5d5f3d06dd

View file

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