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
|
|
|
|
2020-01-22 14:01:35 +00:00
|
|
|
use sharks::{Share, Sharks};
|
2020-01-21 09:09:20 +00:00
|
|
|
|
|
|
|
fn dealer(c: &mut Criterion) {
|
|
|
|
let sharks = Sharks(255);
|
|
|
|
let mut dealer = sharks.dealer(&[1]);
|
2020-01-10 16:08:30 +00:00
|
|
|
|
2020-01-21 09:09:20 +00:00
|
|
|
c.bench_function("obtain_shares_dealer", |b| {
|
|
|
|
b.iter(|| sharks.dealer(black_box(&[1])))
|
2020-01-13 10:42:59 +00:00
|
|
|
});
|
2020-01-21 09:09:20 +00:00
|
|
|
c.bench_function("step_shares_dealer", |b| b.iter(|| dealer.next()));
|
2020-01-10 16:08:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 09:09:20 +00:00
|
|
|
fn recover(c: &mut Criterion) {
|
|
|
|
let sharks = Sharks(255);
|
2020-01-22 14:01:35 +00:00
|
|
|
let shares: Vec<Share> = sharks.dealer(&[1]).take(255).collect();
|
2020-01-10 16:08:30 +00:00
|
|
|
|
2020-01-13 10:42:59 +00:00
|
|
|
c.bench_function("recover_secret", |b| {
|
2020-01-22 14:01:35 +00:00
|
|
|
b.iter(|| sharks.recover(black_box(shares.as_slice())))
|
2020-01-13 10:42:59 +00:00
|
|
|
});
|
2020-01-10 16:08:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:01:35 +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();
|
2020-01-22 14:01:35 +00:00
|
|
|
|
|
|
|
c.bench_function("share_from_bytes", |b| {
|
2021-03-14 16:35:43 +00:00
|
|
|
b.iter(|| Share::try_from(black_box(bytes)))
|
2020-01-22 14:01:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|