blahaj/benches/benchmarks.rs

40 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};
use sharks::{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();
let share = Share::from(bytes);
c.bench_function("share_from_bytes", |b| {
b.iter(|| Share::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);