- 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
@ -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);
|