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`.
kr0 c.perezbaro@gmail.com
Fri, 19 Jul 2019 11:06:38 +0200
2 files changed,
47 insertions(+),
0 deletions(-)
M
shamirsecretsharing-rs/Cargo.toml
→
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
A
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);