Skip to content

Commit 02109b5

Browse files
committed
Benchmark polynomials of different degrees.
1 parent d783f27 commit 02109b5

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ env:
3030
- RUST_NEXT=nightly-2018-07-13
3131
script:
3232
- cargo +${RUST_NEXT} clippy -- --deny clippy
33-
- cargo +${RUST_NEXT} clippy --tests --examples -- --deny clippy
33+
- cargo +${RUST_NEXT} clippy --tests --examples --benches -- --deny clippy
3434
- cargo +${RUST_NEXT} clippy --all-features -- --deny clippy
3535
- cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy
3636
- cargo +${RUST_NEXT} fmt -- --check

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ Disabling memory locking is useful because it removes the possibility of tests f
6666

6767
## Application Details
6868

69-
The basic usage outline is:
69+
The basic usage outline is:
7070
* choose a threshold value `t`
7171
* create a key set
7272
* distribute `N` secret key shares among the participants
73-
* publish the public master key
73+
* publish the public master key
7474

7575
A third party can now encrypt a message to the public master key
7676
and any set of `t + 1` participants *(but no fewer!)* can collaborate to
7777
decrypt it. Also, any set of `t + 1` participants can collaborate to sign a message,
7878
producing a signature that is verifiable with the public master key.
7979

80-
In this system, a signature is unique and independent of
80+
In this system, a signature is unique and independent of
8181
the set of participants that produced it. If `S1` and `S2` are
8282
signatures for the same message, produced by two different sets of `t + 1`
8383
secret key share holders, both signatures will be valid AND

benches/bench.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
#[macro_use]
22
extern crate criterion;
3+
extern crate pairing;
34
extern crate rand;
45
extern crate threshold_crypto;
56

67
use criterion::Criterion;
8+
use pairing::bls12_381::Fr;
79
use threshold_crypto::poly::Poly;
810

911
mod poly_benches {
1012
use super::*;
13+
use rand::Rng;
1114

12-
// Benchmarks multiplication of two degree 3 polynomials.
15+
// Benchmarks multiplication of two polynomials.
1316
fn multiplication(c: &mut Criterion) {
1417
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+
c.bench_function_over_inputs(
19+
"Polynomial multiplication",
20+
move |b, &&deg| {
21+
let rand_factors = || {
22+
let lhs = Poly::random(deg, &mut rng).unwrap();
23+
let rhs = Poly::random(deg, &mut rng).unwrap();
24+
(lhs, rhs)
25+
};
26+
b.iter_with_setup(rand_factors, |(lhs, rhs)| &lhs * &rhs)
27+
},
28+
&[5, 10, 20, 40],
29+
);
1830
}
1931

20-
// Benchmarks Lagrange interpolation for a degree 3 polynomial.
32+
// Benchmarks Lagrange interpolation for a polynomial.
2133
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-
});
34+
let mut rng = rand::thread_rng();
35+
c.bench_function_over_inputs(
36+
"Polynomial interpolation",
37+
move |b, &&deg| {
38+
let rand_samples = || (0..=deg).map(|i| (i, rng.gen::<Fr>())).collect::<Vec<_>>();
39+
b.iter_with_setup(rand_samples, |samples| Poly::interpolate(samples).unwrap())
40+
},
41+
&[5, 10, 20, 40],
42+
);
2743
}
2844

2945
criterion_group!{

0 commit comments

Comments
 (0)