fork of https://github.com/poanetwork/threshold_crypto for the needs of nextgraph.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
#[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 polynomials.
|
|
fn multiplication(c: &mut Criterion) {
|
|
let mut rng = rand::thread_rng();
|
|
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 polynomial.
|
|
fn interpolate(c: &mut Criterion) {
|
|
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::<Fr>())).collect::<Vec<_>>();
|
|
b.iter_with_setup(rand_samples, |samples| Poly::interpolate(samples).unwrap())
|
|
},
|
|
&[5, 10, 20, 40],
|
|
);
|
|
}
|
|
|
|
criterion_group!{
|
|
name = poly_benches;
|
|
config = Criterion::default();
|
|
targets = multiplication, interpolate,
|
|
}
|
|
}
|
|
|
|
criterion_main!(poly_benches::poly_benches);
|
|
|