Add benchmarking subcommand

The benchmarking subcommand returns the time it takes to

...create a sha256 hash
...create a sha512 hash
...encrypt some data via des
...decrypt des encrypted data

Each benchmark is run 1 Million times and the average result as well as the
standard deviation is returned.
master
Trivernis 4 years ago
parent 211ece2265
commit 564c23a511

11
Cargo.lock generated

@ -61,6 +61,15 @@ dependencies = [
"xz2 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "benchlib-rs"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.2.1"
@ -223,6 +232,7 @@ version = "0.1.0"
dependencies = [
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bdflib 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"benchlib-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cfb-mode 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"des 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -816,6 +826,7 @@ dependencies = [
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
"checksum bdflib 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3462a43309b1dcdf09f2158552e19e48b27ddf77cfdcbf28bf716153b5bcded0"
"checksum benchlib-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "57e08932403b5810697eb9759dcaf839d1f03d65192b1dbbba5a888ae10d4e85"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"

@ -19,4 +19,5 @@ pbr = "1.0.2"
spinners = "1.2.0"
regex = "1.3.4"
byteorder = "1.3.4"
bdflib = "0.2.0"
bdflib = "0.2.0"
benchlib-rs = "0.3.4"

@ -3,10 +3,11 @@ pub mod lib;
use crate::lib::crypt::{
decrypt_brute_brute_force, decrypt_data, decrypt_with_dictionary, encrypt_data,
};
use crate::lib::hash::{create_key, sha256, sha_checksum};
use crate::lib::hash::{create_key, sha256, sha512, sha_checksum};
use crate::lib::timing::TimeTaker;
use bdf::chunks::{DataEntry, HashEntry, HashLookupTable};
use bdf::io::{BDFReader, BDFWriter};
use benchlib::benching::Bencher;
use pbr::ProgressBar;
use rayon::prelude::*;
use rayon::str;
@ -42,6 +43,10 @@ enum SubCommand {
/// Create a dictionary rainbow-table from a txt file
#[structopt(name = "create-dictionary")]
CreateDictionary(CreateDictionary),
/// Runs some benchmarks
#[structopt(name = "benchmark")]
Benchmark,
}
#[derive(StructOpt, Clone)]
@ -106,6 +111,7 @@ fn main() {
SubCommand::Encrypt(args) => encrypt(&opts, &args),
SubCommand::Decrypt(args) => decrypt(&opts, &args),
SubCommand::CreateDictionary(args) => create_dictionary(&opts, &args),
SubCommand::Benchmark => benchmark(),
}
}
@ -299,3 +305,19 @@ fn decrypt_with_dictionary_file(
pb.finish();
result_data
}
fn benchmark() {
let mut bencher = Bencher::new();
let mut test_key = Vec::new();
let mut encrypted = Vec::new();
bencher
.set_iterations(1_000_000)
.print_settings()
.bench("sha256", || test_key = sha256("abcdefghijklmnopqrstuvwxyz"))
.bench("sha512", || sha512("abcdefghijklmnopqrstuvwxyz"))
.compare()
.bench("des encrypt", || {
encrypted = encrypt_data(b"abcdefghijklmnopqrstuvwxyz", &test_key[..8])
})
.bench("des decrypt", || decrypt_data(&encrypted, &test_key[..8]));
}

Loading…
Cancel
Save