Skip to content

Commit

Permalink
add beltdwp bench
Browse files Browse the repository at this point in the history
  • Loading branch information
makavity committed May 18, 2024
1 parent 640e43b commit 99de170
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions benches/src/betldwp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

use belt_dwp::aead::{Aead, KeyInit};
use belt_dwp::BeltDwp;

const KB: usize = 1024;

#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
type Benchmarker = Criterion;
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
type Benchmarker = Criterion<criterion_cycles_per_byte::CyclesPerByte>;

fn bench(c: &mut Benchmarker) {
let mut group = c.benchmark_group("beltdwp");

for size in &[KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB] {
let buf = vec![0u8; *size];

group.throughput(Throughput::Bytes(*size as u64));

group.bench_function(BenchmarkId::new("encrypt", size), |b| {
let cipher = BeltDwp::new(&Default::default());
b.iter(|| cipher.encrypt(&Default::default(), &*buf))
});
group.bench_function(BenchmarkId::new("decrypt", size), |b| {
let cipher = BeltDwp::new(&Default::default());
b.iter(|| cipher.decrypt(&Default::default(), &*buf))
});
}

group.finish();
}

#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
criterion_group!(
name = benches;
config = Criterion::default();
targets = bench
);

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
criterion_group!(
name = benches;
config = Criterion::default().with_measurement(criterion_cycles_per_byte::CyclesPerByte);
targets = bench
);

criterion_main!(benches);

0 comments on commit 99de170

Please sign in to comment.