diff --git a/Cargo.lock b/Cargo.lock index e96c60949..975aec7cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3426,6 +3426,7 @@ dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3436,6 +3437,7 @@ dependencies = [ "solana-stake-api 0.20.0", "solana-storage-api 0.20.0", "solana-vote-api 0.20.0", + "sys-info 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/genesis/Cargo.toml b/genesis/Cargo.toml index af7ac4fba..d225ff389 100644 --- a/genesis/Cargo.toml +++ b/genesis/Cargo.toml @@ -23,3 +23,5 @@ solana-stake-api = { path = "../programs/stake_api", version = "0.20.0" } solana-storage-api = { path = "../programs/storage_api", version = "0.20.0" } solana-vote-api = { path = "../programs/vote_api", version = "0.20.0" } tempfile = "3.1.0" +sys-info = "0.5.8" +rayon = "1.2.0" \ No newline at end of file diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 0882ff606..685d34f98 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -2,6 +2,7 @@ use base64; use clap::{crate_description, crate_name, crate_version, value_t_or_exit, App, Arg}; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; use solana_core::blocktree::create_new_ledger; use solana_genesis::PrimordialAccountDetails; use solana_sdk::{ @@ -376,12 +377,18 @@ fn main() -> Result<(), Box> { match matches.value_of("hashes_per_tick").unwrap() { "auto" => { - let mut v = Hash::default(); - println!("Running 1 million hashes..."); + let v = Hash::default(); + // calculate hash rate with the system under maximum load + println!("Running 1 million hashes in parallel on all threads..."); let start = Instant::now(); - for _ in 0..1_000_000 { - v = hash(&v.as_ref()); - } + (0..sys_info::cpu_num().unwrap()) + .into_par_iter() + .for_each_with(v, |v, _| { + for _ in 0..1_000_000 { + *v = hash(&v.as_ref()); + } + }); + let end = Instant::now(); let elapsed = end.duration_since(start).as_millis();