Benchmark polynomials of different degrees.

master
Andreas Fackler 7 years ago committed by Andreas Fackler
parent d783f2756e
commit 02109b586e
  1. 2
      .travis.yml
  2. 36
      benches/bench.rs

@ -30,7 +30,7 @@ env:
- RUST_NEXT=nightly-2018-07-13 - RUST_NEXT=nightly-2018-07-13
script: script:
- cargo +${RUST_NEXT} clippy -- --deny clippy - 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 -- --deny clippy
- cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy - cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy
- cargo +${RUST_NEXT} fmt -- --check - cargo +${RUST_NEXT} fmt -- --check

@ -1,29 +1,45 @@
#[macro_use] #[macro_use]
extern crate criterion; extern crate criterion;
extern crate pairing;
extern crate rand; extern crate rand;
extern crate threshold_crypto; extern crate threshold_crypto;
use criterion::Criterion; use criterion::Criterion;
use pairing::bls12_381::Fr;
use threshold_crypto::poly::Poly; use threshold_crypto::poly::Poly;
mod poly_benches { mod poly_benches {
use super::*; use super::*;
use rand::Rng;
// Benchmarks multiplication of two degree 3 polynomials. // Benchmarks multiplication of two polynomials.
fn multiplication(c: &mut Criterion) { fn multiplication(c: &mut Criterion) {
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
let lhs = Poly::random(3, &mut rng).unwrap(); c.bench_function_over_inputs(
let rhs = Poly::random(3, &mut rng).unwrap(); "Polynomial multiplication",
c.bench_function("Polynomial multiplication", move |b| b.iter(|| &lhs * &rhs)); move |b, &&deg| {
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) { fn interpolate(c: &mut Criterion) {
// Points from the the polynomial: `y(x) = 5x^3 + 0x^2 + x - 2`. let mut rng = rand::thread_rng();
let sample_points = vec![(-1, -8), (2, 40), (3, 136), (5, 628)]; c.bench_function_over_inputs(
c.bench_function("Polynomial interpolation", move |b| { "Polynomial interpolation",
b.iter(|| Poly::interpolate(sample_points.clone()).unwrap()) move |b, &&deg| {
}); let rand_samples = || (0..=deg).map(|i| (i, rng.gen::<Fr>())).collect::<Vec<_>>();
b.iter_with_setup(rand_samples, |samples| Poly::interpolate(samples).unwrap())
},
&[5, 10, 20, 40],
);
} }
criterion_group!{ criterion_group!{

Loading…
Cancel
Save