Skip to content

Commit

Permalink
Add iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Dec 14, 2024
1 parent 16644b4 commit f57fb6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ Options:
### Running Stability Tests
```sh
Run stability test
Run stability tests

Usage: slowkey stability-test --tasks <THREADS>
Usage: slowkey stability-test [OPTIONS] --tasks <TASKS>

Options:
-t, --tasks <THREADS> Number of tasks
-h, --help Print help
-t, --tasks <TASKS> Number of tasks
-i, --iterations <ITERATIONS> Number of iterations to perform (must be greater than 0 and lesser than 2000) [default: 2000]
-h, --help Print help
```
## Build
Expand Down Expand Up @@ -829,7 +830,7 @@ In order to run stability tests, you can run the `stability-test` command and sp
> slowkey stability-test -t 8
```sh
Setting up a stability test task pool with 8 tasks
Setting up a stability test task pool with 8 tasks, each running 2000 iterations
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3/2000 0% (4h)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3/2000 0% (4h)
Expand Down
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use humantime::format_duration;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use mimalloc::MiMalloc;
use sha2::{Digest, Sha512};
use stability::STABILITY_TEST_ITERATIONS;
use std::{
cmp::Ordering,
collections::VecDeque,
Expand Down Expand Up @@ -290,6 +291,13 @@ enum Commands {
StabilityTest {
#[arg(long, short, help = "Number of tasks")]
tasks: usize,

#[arg(
long,
short,
default_value = STABILITY_TEST_ITERATIONS.to_string(),
help = format!("Number of iterations to perform (must be greater than {} and lesser than {})", 0, STABILITY_TEST_ITERATIONS))]
iterations: usize,
},
}

Expand Down Expand Up @@ -1118,8 +1126,8 @@ fn main() {

println!("Saved benchmark reports to: \"{}\"", output_path.to_string_lossy());
},
Some(Commands::StabilityTest { tasks }) => {
stability_test(tasks);
Some(Commands::StabilityTest { tasks, iterations }) => {
stability_test(tasks, iterations);
},
None => {},
}
Expand Down
16 changes: 10 additions & 6 deletions src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::process::{self};

const TEST_SALT: &str = "saltsaltsaltsalt";
const TEST_PASSWORD: &str = "password";
const ITERATIONS: usize = 2000;
const EXPECTED: [&str; ITERATIONS] = [
pub const STABILITY_TEST_ITERATIONS: usize = 2000;
const EXPECTED: [&str; STABILITY_TEST_ITERATIONS] = [
"392ddd7c90c91ca9ec1814f50a69ed82e489da4a4eb064dee8029a1a9baafc8e",
"9e337dd977ddba27adafb52c4209a2f8aa002494432063a642b4547fde14e1d8",
"b7520f0d5a2b09f1ca04e95db78dfc7be9fc081dbbbd5b9d9bf229cbea2f8799",
Expand Down Expand Up @@ -2013,24 +2013,28 @@ const EXPECTED: [&str; ITERATIONS] = [
"cf47a21d7876e09751c534db476c71689ba52b7c85f0f84945e3fa5c27b736af",
];

pub fn stability_test(tasks: usize) {
pub fn stability_test(tasks: usize, iterations: usize) {
if tasks == 0 {
panic!("Invalid number of tasks");
}

if iterations == 0 || iterations > STABILITY_TEST_ITERATIONS {
panic!("Invalid number of iterations");
}

println!(
"{}: If the requested number of tasks {tasks} is greater than the maximum thread count available by the OS it can result in some of tasks being stalled\n",
"Warning".dark_yellow(),
);

println!("Setting up a stability test task pool with {tasks} tasks");
println!("Setting up a stability test task pool with {tasks} tasks, each running {iterations} iterations");
println!();

let mb = MultiProgress::new();
let mut pbs = Vec::new();
for i in 0..tasks {
let pb = mb
.add(ProgressBar::new(ITERATIONS as u64))
.add(ProgressBar::new(iterations as u64))
.with_style(
ProgressStyle::with_template("{bar:80.cyan/blue} {msg} {pos:>4}/{len:8} {percent}% ({eta})")
.unwrap(),
Expand All @@ -2046,7 +2050,7 @@ pub fn stability_test(tasks: usize) {
let pb = &pbs[i];

let slowkey = SlowKey::new(&SlowKeyOptions {
iterations: ITERATIONS,
iterations,
length: SlowKeyOptions::DEFAULT_OUTPUT_SIZE,
scrypt: ScryptOptions::default(),
argon2id: Argon2idOptions::default(),
Expand Down

0 comments on commit f57fb6d

Please sign in to comment.