#[macro_use] extern crate criterion; extern crate libss; use criterion::black_box; use criterion::Criterion; use libss::gf256::GF256; use libss::shamir::Shamir; use libss::Field; use rand::Rng; fn bench_gf256_add(c: &mut Criterion) { let (x, y) = rand::thread_rng().gen::<(GF256, GF256)>(); c.bench_function("gf256_add", move |b| { b.iter(|| { let z = x + y; black_box(z); }) }); } fn bench_gf256_mul(c: &mut Criterion) { let (x, y) = rand::thread_rng().gen::<(GF256, GF256)>(); c.bench_function("gf256_mul", move |b| { b.iter(|| { let z = x * y; black_box(z); }) }); } fn bench_gf256_inv(c: &mut Criterion) { let x = rand::thread_rng().gen::(); c.bench_function("gf256_inv", move |b| { b.iter(|| { let z = x.inverse().unwrap(); black_box(z); }) }); } // Create gf256 benchmark group criterion_group!(gf256, bench_gf256_add, bench_gf256_inv, bench_gf256_mul); fn bench_split(c: &mut Criterion) { let secret = (0..1024) .map(|_| rand::thread_rng().gen::()) .collect::>(); let k = 3; let n = 5; c.bench_function("split 3 of 5", move |b| { b.iter(|| { let shares = Shamir::split(&secret, k, n).unwrap(); black_box(shares); }) }); } fn bench_combine(c: &mut Criterion) { let secret = (0..1024) .map(|_| rand::thread_rng().gen::()) .collect::>(); let k = 3; let n = 5; let shares = Shamir::split(&secret, k, n).unwrap(); c.bench_function("combine 3 of 5", move |b| { b.iter(|| { let recovered_secret = Shamir::combine(&shares); black_box(recovered_secret); }) }); } // Create shamir benchmark group criterion_group!(shamir, bench_split, bench_combine); // Run all benchmark groups listed here criterion_main!(shamir, gf256);