summary refs log tree commit diff
path: root/ripple/fossil/benches/chunker.rs
blob: 75e3299796ffd7856e49782b6fc01735bde131f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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);