Browse Source

Implement Benchmarks for modular inverse impl

- Added `Criterion` on dev-dependencies and a
benches config section on Cargo.toml

- Added `benchmarks` folder with `benches.rs` file.

This file contains the benchmarks implementation of
the two distinct modular_inverse implementations.

Results:
```
Modular Inverse/Kalinski Modular inverse
                        time:   [50.105 us 50.438 us 50.819 us]
                        change: [-44.740% -44.195% -43.664%] (p = 0.00 < 0.05)
                        Performance has improved.

Modular Inverse/Standard Mod Inv
                        time:   [82.301 us 82.430 us 82.580 us]
```

To run the benchmarks just run: `cargo bench`.
pull/2/head
kr0 4 years ago
parent
commit
a430ae3d04
2 changed files with 47 additions and 0 deletions
  1. +9
    -0
      shamirsecretsharing-rs/Cargo.toml
  2. +38
    -0
      shamirsecretsharing-rs/benchmarks/benches.rs

+ 9
- 0
shamirsecretsharing-rs/Cargo.toml

@ -9,3 +9,12 @@ rand = "0.6.5"
num = "0.2.0"
num-bigint = {version = "0.2.2", features = ["rand"]}
num-traits = "0.2.8"
[dev-dependencies]
criterion = "0.2"
# Criterion benchmarks
[[bench]]
path = "./benchmarks/benches.rs"
name = "benches"
harness = false

+ 38
- 0
shamirsecretsharing-rs/benchmarks/benches.rs

@ -0,0 +1,38 @@
#[macro_use]
extern crate criterion;
extern crate shamirsecretsharing_rs;
extern crate num_bigint;
use criterion::{Criterion, Benchmark};
use shamirsecretsharing_rs::*;
use num_bigint::BigInt;
use std::str::FromStr;
mod mod_inv_benches {
use super::*;
pub fn bench_modular_inv(c: &mut Criterion) {
let modul1 = BigInt::from_str("7237005577332262213973186563042994240857116359379907606001950938285454250989").unwrap();
let d1 = BigInt::from_str("182687704666362864775460604089535377456991567872").unwrap();
let modul2 = BigInt::from_str("7237005577332262213973186563042994240857116359379907606001950938285454250989").unwrap();
let d2 = BigInt::from_str("182687704666362864775460604089535377456991567872").unwrap();
c.bench(
"Modular Inverse",
Benchmark::new("Kalinski Modular inverse", move |b| b.iter(|| kalinski_inv(&d1, &modul1)))
);
c.bench(
"Modular Inverse",
Benchmark::new("Standard Mod Inv", move |b| b.iter(|| mod_inverse(d2.clone(), modul2.clone())))
);
}
}
criterion_group!(benches,
mod_inv_benches::bench_modular_inv);
criterion_main!(benches);

Loading…
Cancel
Save