diff --git a/src/main.rs b/src/main.rs index f392543..477d25d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use clap::Parser; use pow_sha256::ConfigBuilder; +use rayon::prelude::*; use serde::{Deserialize, Serialize}; use std::time::Instant; @@ -36,28 +37,29 @@ impl GenerateDeriveArgs { let string = get_random(32); let pow_config = ConfigBuilder::default().salt(salt.clone()).build().unwrap(); - for difficulty in self.start..self.max { - let start = Instant::now(); - pow_config.prove_work(&string, difficulty).unwrap(); - let finish = Instant::now(); - let time_elapsed = finish.duration_since(start); + (self.start..self.max) + .into_par_iter() + .for_each(|difficulty| { + let start = Instant::now(); + pow_config.prove_work(&string, difficulty).unwrap(); + let finish = Instant::now(); + let time_elapsed = finish.duration_since(start); - let time= time_elapsed.as_micros(); - log::info!("Difficulty factor {difficulty} generated in {time}"); + let time = time_elapsed.as_micros(); + log::info!("Difficulty factor {difficulty} generated in {time}"); + let log = Log { + salt: salt.clone(), + time, + string: string.clone(), + }; - let log = Log { - salt: salt.clone(), - time, - string: string.clone(), - }; - - db.insert( - bincode::serialize(&difficulty).unwrap(), - bincode::serialize(&log).unwrap(), - ) - .unwrap(); - } + db.insert( + bincode::serialize(&difficulty).unwrap(), + bincode::serialize(&log).unwrap(), + ) + .unwrap(); + }); } }