From 972697976c027b5199150a98e886c199b7ffc335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Fri, 6 Dec 2024 16:18:03 +0100 Subject: [PATCH] bench: make ObfuscationBench more representative A previous PR already solved the tiny byte-array-xors during serialization, so it makes sense to keep focusing on the performance of bigger continuous chunks. This also renames the file from `xor` to `obfuscation` to enable scripted diff name unification later. > C++ compiler .......................... GNU 14.2.0 | ns/byte | byte/s | err% | ins/byte | cyc/byte | IPC | bra/byte | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 0.84 | 1,184,138,235.64 | 0.0% | 9.01 | 3.03 | 2.971 | 1.00 | 0.1% | 5.50 | `ObfuscationBench` > C++ compiler .......................... Clang 20.1.7 | ns/byte | byte/s | err% | ins/byte | cyc/byte | IPC | bra/byte | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 0.89 | 1,124,087,330.23 | 0.1% | 6.52 | 3.20 | 2.041 | 0.50 | 0.2% | 5.50 | `ObfuscationBench` --- src/bench/CMakeLists.txt | 2 +- src/bench/{xor.cpp => obfuscation.cpp} | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) rename src/bench/{xor.cpp => obfuscation.cpp} (59%) diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index 2137beccb5a..9f161876150 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -35,6 +35,7 @@ add_executable(bench_bitcoin mempool_eviction.cpp mempool_stress.cpp merkle_root.cpp + obfuscation.cpp parse_hex.cpp peer_eviction.cpp poly1305.cpp @@ -51,7 +52,6 @@ add_executable(bench_bitcoin txgraph.cpp util_time.cpp verify_script.cpp - xor.cpp ) include(TargetDataSources) diff --git a/src/bench/xor.cpp b/src/bench/obfuscation.cpp similarity index 59% rename from src/bench/xor.cpp rename to src/bench/obfuscation.cpp index f3d6145c2b2..27a254f8037 100644 --- a/src/bench/xor.cpp +++ b/src/bench/obfuscation.cpp @@ -4,22 +4,23 @@ #include #include -#include #include #include #include #include -static void Xor(benchmark::Bench& bench) +static void ObfuscationBench(benchmark::Bench& bench) { FastRandomContext frc{/*fDeterministic=*/true}; auto data{frc.randbytes(1024)}; - auto key{frc.randbytes(Obfuscation::KEY_SIZE)}; + const auto key{frc.randbytes()}; + size_t offset{0}; bench.batch(data.size()).unit("byte").run([&] { - util::Xor(data, key); + util::Xor(data, key, offset++); // mutated differently each time + ankerl::nanobench::doNotOptimizeAway(data); }); } -BENCHMARK(Xor, benchmark::PriorityLevel::HIGH); +BENCHMARK(ObfuscationBench, benchmark::PriorityLevel::HIGH);