Added benchmarks for polynomial multiplication and interpolation.
This commit is contained in:
parent
2f3b061b82
commit
d783f2756e
|
@ -28,4 +28,10 @@ tiny-keccak = "1.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bincode = "1.0.0"
|
bincode = "1.0.0"
|
||||||
|
criterion = "0.2"
|
||||||
|
rand = "0.4.2"
|
||||||
serde_derive = "1.0.55"
|
serde_derive = "1.0.55"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "bench"
|
||||||
|
harness = false
|
||||||
|
|
11
README.md
11
README.md
|
@ -93,6 +93,17 @@ must tolerate up to `t` adversarial (malicious or faulty) nodes. Because `t +
|
||||||
1` nodes are required to sign or reveal information, messages can be trusted
|
1` nodes are required to sign or reveal information, messages can be trusted
|
||||||
by third-parties as representing the consensus of the network.
|
by third-parties as representing the consensus of the network.
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
Benchmarking functionality is kept in the [`benches` directory](benches). You
|
||||||
|
can run the benchmarks with the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ RUSTFLAGS="-C target_cpu=native" cargo bench
|
||||||
|
```
|
||||||
|
|
||||||
|
We use the [`criterion`](https://crates.io/crates/criterion) benchmarking library.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Licensed under either of:
|
Licensed under either of:
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#[macro_use]
|
||||||
|
extern crate criterion;
|
||||||
|
extern crate rand;
|
||||||
|
extern crate threshold_crypto;
|
||||||
|
|
||||||
|
use criterion::Criterion;
|
||||||
|
use threshold_crypto::poly::Poly;
|
||||||
|
|
||||||
|
mod poly_benches {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
// Benchmarks multiplication of two degree 3 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmarks Lagrange interpolation for a degree 3 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())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!{
|
||||||
|
name = poly_benches;
|
||||||
|
config = Criterion::default();
|
||||||
|
targets = multiplication, interpolate,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_main!(poly_benches::poly_benches);
|
Loading…
Reference in New Issue