blahaj/benches/benchmarks.rs

27 lines
891 B
Rust
Raw Normal View History

2020-01-10 16:08:30 +00:00
use std::collections::HashMap;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use sharks::SecretShares;
fn secret_shares_generation(c: &mut Criterion) {
let shamir = SecretShares::new(1000, 128).unwrap();
let mut iter = shamir.iter_shares(12345).unwrap();
c.bench_function("obtain_shares_iterator", |b| {
b.iter(|| shamir.iter_shares(black_box(12345)))
});
2020-01-10 16:08:30 +00:00
c.bench_function("step_shares_iterator", |b| b.iter(|| iter.next()));
}
fn secret_from_shares(c: &mut Criterion) {
let shamir = SecretShares::new(10, 128).unwrap();
let shares: HashMap<u128, u128> = shamir.iter_shares(12345).unwrap().take(100).collect();
2020-01-10 16:08:30 +00:00
c.bench_function("recover_secret", |b| {
b.iter(|| shamir.secret_from(black_box(&shares)))
});
2020-01-10 16:08:30 +00:00
}
criterion_group!(benches, secret_shares_generation, secret_from_shares);
criterion_main!(benches);