mirror of
https://github.com/arnaucube/shamirsecretsharing.git
synced 2026-02-06 19:16:46 +01:00
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`.
This commit is contained in:
@@ -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
shamirsecretsharing-rs/benchmarks/benches.rs
Normal file
38
shamirsecretsharing-rs/benchmarks/benches.rs
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user