summary refs log tree commit diff
path: root/ripple/fossil/benches
diff options
context:
space:
mode:
Diffstat (limited to 'ripple/fossil/benches')
-rw-r--r--ripple/fossil/benches/chunker.rs37
1 files changed, 37 insertions, 0 deletions
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 <edef@unfathomable.blue>
+// 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<u8> {
+	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);