blahaj/benches/benchmarks.rs

41 lines
1.1 KiB
Rust
Raw Normal View History

2020-01-10 16:08:30 +00:00
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2021-03-14 16:35:43 +00:00
use std::convert::TryFrom;
2020-01-10 16:08:30 +00:00
2024-11-17 00:11:25 +00:00
use blahaj::{Share, Sharks};
fn dealer(c: &mut Criterion) {
let sharks = Sharks(255);
let mut dealer = sharks.dealer(&[1]);
2020-01-10 16:08:30 +00:00
c.bench_function("obtain_shares_dealer", |b| {
b.iter(|| sharks.dealer(black_box(&[1])))
});
c.bench_function("step_shares_dealer", |b| b.iter(|| dealer.next()));
2020-01-10 16:08:30 +00:00
}
fn recover(c: &mut Criterion) {
let sharks = Sharks(255);
let shares: Vec<Share> = sharks.dealer(&[1]).take(255).collect();
2020-01-10 16:08:30 +00:00
c.bench_function("recover_secret", |b| {
b.iter(|| sharks.recover(black_box(shares.as_slice())))
});
2020-01-10 16:08:30 +00:00
}
fn share(c: &mut Criterion) {
let bytes_vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let bytes = bytes_vec.as_slice();
2021-03-14 16:35:43 +00:00
let share = Share::try_from(bytes).unwrap();
c.bench_function("share_from_bytes", |b| {
2021-03-14 16:35:43 +00:00
b.iter(|| Share::try_from(black_box(bytes)))
});
c.bench_function("share_to_bytes", |b| {
b.iter(|| Vec::from(black_box(&share)))
});
}
criterion_group!(benches, dealer, recover, share);
2020-01-10 16:08:30 +00:00
criterion_main!(benches);