Skip to content

Commit d783f27

Browse files
DrPeterVanNostrandafck
authored andcommitted
Added benchmarks for polynomial multiplication and interpolation.
1 parent 2f3b061 commit d783f27

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ tiny-keccak = "1.4"
2828

2929
[dev-dependencies]
3030
bincode = "1.0.0"
31+
criterion = "0.2"
32+
rand = "0.4.2"
3133
serde_derive = "1.0.55"
34+
35+
[[bench]]
36+
name = "bench"
37+
harness = false

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ must tolerate up to `t` adversarial (malicious or faulty) nodes. Because `t +
9393
1` nodes are required to sign or reveal information, messages can be trusted
9494
by third-parties as representing the consensus of the network.
9595

96+
## Performance
97+
98+
Benchmarking functionality is kept in the [`benches` directory](benches). You
99+
can run the benchmarks with the following command:
100+
101+
```
102+
$ RUSTFLAGS="-C target_cpu=native" cargo bench
103+
```
104+
105+
We use the [`criterion`](https://crates.io/crates/criterion) benchmarking library.
106+
96107
## License
97108

98109
Licensed under either of:

benches/bench.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
extern crate rand;
4+
extern crate threshold_crypto;
5+
6+
use criterion::Criterion;
7+
use threshold_crypto::poly::Poly;
8+
9+
mod poly_benches {
10+
use super::*;
11+
12+
// Benchmarks multiplication of two degree 3 polynomials.
13+
fn multiplication(c: &mut Criterion) {
14+
let mut rng = rand::thread_rng();
15+
let lhs = Poly::random(3, &mut rng).unwrap();
16+
let rhs = Poly::random(3, &mut rng).unwrap();
17+
c.bench_function("Polynomial multiplication", move |b| b.iter(|| &lhs * &rhs));
18+
}
19+
20+
// Benchmarks Lagrange interpolation for a degree 3 polynomial.
21+
fn interpolate(c: &mut Criterion) {
22+
// Points from the the polynomial: `y(x) = 5x^3 + 0x^2 + x - 2`.
23+
let sample_points = vec![(-1, -8), (2, 40), (3, 136), (5, 628)];
24+
c.bench_function("Polynomial interpolation", move |b| {
25+
b.iter(|| Poly::interpolate(sample_points.clone()).unwrap())
26+
});
27+
}
28+
29+
criterion_group!{
30+
name = poly_benches;
31+
config = Criterion::default();
32+
targets = multiplication, interpolate,
33+
}
34+
}
35+
36+
criterion_main!(poly_benches::poly_benches);

0 commit comments

Comments
 (0)