diff options
author | edef <edef@unfathomable.blue> | 2022-05-01 18:53:01 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-05-01 18:53:01 +0000 |
commit | acc115945c7788dea022a0899580e4326cf760a4 (patch) | |
tree | 13bba3255ec55f7c32bc4b17fd0eae652027a299 /ripple/fossil | |
parent | 035650d64b60a2f31af3ac8e26c3e7fbd2b6ca1b (diff) | |
download | unf-legacy-acc115945c7788dea022a0899580e4326cf760a4.tar.zst |
ripple/fossil: benchmark Chunker using Criterion
Performance hovers around 300MiB/s on my machine. Change-Id: I387ccbf065c0b667824ede0675e6a295722f6d4b
Diffstat (limited to 'ripple/fossil')
-rw-r--r-- | ripple/fossil/Cargo.toml | 7 | ||||
-rw-r--r-- | ripple/fossil/benches/chunker.rs | 37 | ||||
-rw-r--r-- | ripple/fossil/src/lib.rs | 2 |
3 files changed, 45 insertions, 1 deletions
diff --git a/ripple/fossil/Cargo.toml b/ripple/fossil/Cargo.toml index 04d0824..4008691 100644 --- a/ripple/fossil/Cargo.toml +++ b/ripple/fossil/Cargo.toml @@ -22,3 +22,10 @@ anyhow = "1.0.53" [build-dependencies] prost-build = "0.8.0" + +[dev-dependencies] +criterion = "0.3.5" + +[[bench]] +name = "chunker" +harness = false 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); diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 9001102..f4ea3cc 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: edef <edef@unfathomable.blue> // SPDX-License-Identifier: OSL-3.0 +pub use crate::chunker::Chunker; use { - crate::chunker::Chunker, anyhow::{Context, Result}, byteorder::{BigEndian, ByteOrder}, prost::Message, |