Skip to content

Commit

Permalink
bench: Benchmark header parser
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Aug 7, 2021
1 parent 346d10c commit fbfc699
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions age/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ bench = false
name = "test_vectors"
required-features = ["ssh"]

[[bench]]
name = "parser"
harness = false

[[bench]]
name = "throughput"
harness = false
Expand Down
48 changes: 48 additions & 0 deletions age/benches/parser.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Recipient>)
.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);

0 comments on commit fbfc699

Please sign in to comment.