feat: parallelize pow gen
This commit is contained in:
parent
4bc6450d22
commit
c4bc8df0b8
1 changed files with 21 additions and 19 deletions
40
src/main.rs
40
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue