diff --git a/age/Cargo.toml b/age/Cargo.toml index b2f5c0c4..51065e8b 100644 --- a/age/Cargo.toml +++ b/age/Cargo.toml @@ -120,6 +120,10 @@ bench = false name = "test_vectors" required-features = ["ssh"] +[[bench]] +name = "parser" +harness = false + [[bench]] name = "throughput" harness = false diff --git a/age/benches/parser.rs b/age/benches/parser.rs new file mode 100644 index 00000000..3672d4fd --- /dev/null +++ b/age/benches/parser.rs @@ -0,0 +1,48 @@ +use age::{x25519, Decryptor, Encryptor, Recipient}; +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; + +#[cfg(unix)] +use pprof::criterion::{Output, PProfProfiler}; + +use std::io::Write; + +fn bench(c: &mut Criterion) { + let recipients: Vec<_> = (0..10) + .map(|_| Box::new(x25519::Identity::generate().to_public())) + .collect(); + let mut group = c.benchmark_group("header"); + + for count in 1..10 { + group.throughput(Throughput::Elements(count as u64)); + group.bench_function(BenchmarkId::new("parse", count), |b| { + let mut encrypted = vec![]; + let mut output = Encryptor::with_recipients( + recipients + .iter() + .take(count) + .cloned() + .map(|r| r as Box) + .collect(), + ) + .wrap_output(&mut encrypted) + .unwrap(); + output.write_all(&[]).unwrap(); + output.finish().unwrap(); + + b.iter(|| Decryptor::new(&encrypted[..])) + }); + } + + group.finish(); +} + +#[cfg(unix)] +criterion_group!( + name = benches; + config = Criterion::default() + .with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = bench +); +#[cfg(not(unix))] +criterion_group!(benches, bench); +criterion_main!(benches);