Skip to content

Commit 9726979

Browse files
committed
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`
1 parent 618a30e commit 9726979

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/bench/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_executable(bench_bitcoin
3535
mempool_eviction.cpp
3636
mempool_stress.cpp
3737
merkle_root.cpp
38+
obfuscation.cpp
3839
parse_hex.cpp
3940
peer_eviction.cpp
4041
poly1305.cpp
@@ -51,7 +52,6 @@ add_executable(bench_bitcoin
5152
txgraph.cpp
5253
util_time.cpp
5354
verify_script.cpp
54-
xor.cpp
5555
)
5656

5757
include(TargetDataSources)

src/bench/xor.cpp renamed to src/bench/obfuscation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44

55
#include <bench/bench.h>
66
#include <random.h>
7-
#include <span.h>
87
#include <streams.h>
98
#include <util/obfuscation.h>
109

1110
#include <cstddef>
1211
#include <vector>
1312

14-
static void Xor(benchmark::Bench& bench)
13+
static void ObfuscationBench(benchmark::Bench& bench)
1514
{
1615
FastRandomContext frc{/*fDeterministic=*/true};
1716
auto data{frc.randbytes<std::byte>(1024)};
18-
auto key{frc.randbytes<std::byte>(Obfuscation::KEY_SIZE)};
17+
const auto key{frc.randbytes<Obfuscation::KEY_SIZE>()};
1918

19+
size_t offset{0};
2020
bench.batch(data.size()).unit("byte").run([&] {
21-
util::Xor(data, key);
21+
util::Xor(data, key, offset++); // mutated differently each time
22+
ankerl::nanobench::doNotOptimizeAway(data);
2223
});
2324
}
2425

25-
BENCHMARK(Xor, benchmark::PriorityLevel::HIGH);
26+
BENCHMARK(ObfuscationBench, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)