mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
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:
parent
3d203c2acf
commit
5d5f3d06dd
1 changed files with 16 additions and 7 deletions
|
@ -6,19 +6,28 @@
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <util/byte_units.h>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <map>
|
||||||
#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([&] {
|
std::vector key_bytes{rng.randbytes<std::byte>(8)};
|
||||||
util::Xor(data, key);
|
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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue