From 02109b586ed35ef99cb26a8012cf9f790704c139 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Thu, 30 Aug 2018 11:06:03 +0200 Subject: [PATCH] Benchmark polynomials of different degrees. --- .travis.yml | 2 +- README.md | 6 +++--- benches/bench.rs | 36 ++++++++++++++++++++++++++---------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 466b2d0..fb007f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ env: - RUST_NEXT=nightly-2018-07-13 script: - cargo +${RUST_NEXT} clippy -- --deny clippy - - cargo +${RUST_NEXT} clippy --tests --examples -- --deny clippy + - cargo +${RUST_NEXT} clippy --tests --examples --benches -- --deny clippy - cargo +${RUST_NEXT} clippy --all-features -- --deny clippy - cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy - cargo +${RUST_NEXT} fmt -- --check diff --git a/README.md b/README.md index 8fe9001..b23e21b 100644 --- a/README.md +++ b/README.md @@ -66,18 +66,18 @@ Disabling memory locking is useful because it removes the possibility of tests f ## Application Details -The basic usage outline is: +The basic usage outline is: * choose a threshold value `t` * create a key set * distribute `N` secret key shares among the participants -* publish the public master key +* publish the public master key A third party can now encrypt a message to the public master key and any set of `t + 1` participants *(but no fewer!)* can collaborate to decrypt it. Also, any set of `t + 1` participants can collaborate to sign a message, producing a signature that is verifiable with the public master key. -In this system, a signature is unique and independent of +In this system, a signature is unique and independent of the set of participants that produced it. If `S1` and `S2` are signatures for the same message, produced by two different sets of `t + 1` secret key share holders, both signatures will be valid AND diff --git a/benches/bench.rs b/benches/bench.rs index 2c5e68f..7974c77 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,29 +1,45 @@ #[macro_use] extern crate criterion; +extern crate pairing; extern crate rand; extern crate threshold_crypto; use criterion::Criterion; +use pairing::bls12_381::Fr; use threshold_crypto::poly::Poly; mod poly_benches { use super::*; + use rand::Rng; - // Benchmarks multiplication of two degree 3 polynomials. + // Benchmarks multiplication of two polynomials. fn multiplication(c: &mut Criterion) { let mut rng = rand::thread_rng(); - let lhs = Poly::random(3, &mut rng).unwrap(); - let rhs = Poly::random(3, &mut rng).unwrap(); - c.bench_function("Polynomial multiplication", move |b| b.iter(|| &lhs * &rhs)); + c.bench_function_over_inputs( + "Polynomial multiplication", + move |b, &°| { + let rand_factors = || { + let lhs = Poly::random(deg, &mut rng).unwrap(); + let rhs = Poly::random(deg, &mut rng).unwrap(); + (lhs, rhs) + }; + b.iter_with_setup(rand_factors, |(lhs, rhs)| &lhs * &rhs) + }, + &[5, 10, 20, 40], + ); } - // Benchmarks Lagrange interpolation for a degree 3 polynomial. + // Benchmarks Lagrange interpolation for a polynomial. fn interpolate(c: &mut Criterion) { - // Points from the the polynomial: `y(x) = 5x^3 + 0x^2 + x - 2`. - let sample_points = vec![(-1, -8), (2, 40), (3, 136), (5, 628)]; - c.bench_function("Polynomial interpolation", move |b| { - b.iter(|| Poly::interpolate(sample_points.clone()).unwrap()) - }); + let mut rng = rand::thread_rng(); + c.bench_function_over_inputs( + "Polynomial interpolation", + move |b, &°| { + let rand_samples = || (0..=deg).map(|i| (i, rng.gen::())).collect::>(); + b.iter_with_setup(rand_samples, |samples| Poly::interpolate(samples).unwrap()) + }, + &[5, 10, 20, 40], + ); } criterion_group!{