Skip to content

Commit

Permalink
Added benchmarks for polynomial multiplication and interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPeterVanNostrand authored and afck committed Aug 30, 2018
1 parent 2f3b061 commit d783f27
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ tiny-keccak = "1.4"

[dev-dependencies]
bincode = "1.0.0"
criterion = "0.2"
rand = "0.4.2"
serde_derive = "1.0.55"

[[bench]]
name = "bench"
harness = false
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

Licensed under either of:
Expand Down
36 changes: 36 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit d783f27

Please sign in to comment.