From acc115945c7788dea022a0899580e4326cf760a4 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 1 May 2022 18:53:01 +0000 Subject: ripple/fossil: benchmark Chunker using Criterion Performance hovers around 300MiB/s on my machine. Change-Id: I387ccbf065c0b667824ede0675e6a295722f6d4b --- ripple/fossil/benches/chunker.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ripple/fossil/benches/chunker.rs (limited to 'ripple/fossil/benches') diff --git a/ripple/fossil/benches/chunker.rs b/ripple/fossil/benches/chunker.rs new file mode 100644 index 0000000..75e3299 --- /dev/null +++ b/ripple/fossil/benches/chunker.rs @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: edef +// SPDX-License-Identifier: OSL-3.0 + +use std::time::Duration; + +use { + criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}, + fossil::Chunker, + std::io::Read, +}; + +fn generate(length: usize) -> Vec { + let mut h = blake3::Hasher::new(); + h.update(b"test vector"); + let mut buf = vec![0; length]; + h.finalize_xof().read_exact(&mut buf).unwrap(); + buf +} + +fn criterion_benchmark(c: &mut Criterion) { + let data = generate(1024 * 1024 * 64); + + let mut group = c.benchmark_group("chunk"); + group.throughput(Throughput::Bytes(data.len() as u64)); + group.measurement_time(Duration::from_secs(30)); + group.bench_function("iter", |b| { + b.iter(|| { + for chunk in Chunker::from(black_box(&data)) { + black_box(chunk); + } + }) + }); + group.finish(); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); -- cgit 1.4.1