diff --git a/src/args.rs b/src/args.rs index b8fbdeba..1c8fd955 100644 --- a/src/args.rs +++ b/src/args.rs @@ -16,10 +16,10 @@ pub struct BenchmarkArgs { long, short, value_name = "THREAD_COUNT", - help = "The number of threads to use during the benchmark", + help = "The number of cores to use during the benchmark", default_value = "1" )] - pub threads: u64, + pub cores: u64, } #[derive(Parser, Debug)] diff --git a/src/benchmark.rs b/src/benchmark.rs index f8aa4a0b..bb6972bf 100644 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -1,5 +1,6 @@ use std::{sync::Arc, time::Instant}; +use drillx::equix; use solana_rpc_client::spinner; use crate::{args::BenchmarkArgs, Miner}; @@ -9,7 +10,7 @@ const TEST_DURATION: i64 = 30; impl Miner { pub async fn benchmark(&self, args: BenchmarkArgs) { // Check num threads - self.check_num_cores(args.threads); + self.check_num_cores(args.cores); // Dispatch job to each thread let challenge = [0; 32]; @@ -18,16 +19,33 @@ impl Miner { "Benchmarking. This will take {} sec...", TEST_DURATION )); - let handles: Vec<_> = (0..args.threads) + let core_ids = core_affinity::get_core_ids().unwrap(); + let handles: Vec<_> = core_ids + .into_iter() .map(|i| { std::thread::spawn({ move || { let timer = Instant::now(); - let first_nonce = u64::MAX.saturating_div(args.threads).saturating_mul(i); + let first_nonce = u64::MAX + .saturating_div(args.cores) + .saturating_mul(i.id as u64); let mut nonce = first_nonce; + let mut memory = equix::SolverMemory::new(); loop { + // Return if core should not be used + if (i.id as u64).ge(&args.cores) { + return 0; + } + + // Pin to core + let _ = core_affinity::set_for_current(i); + // Create hash - let _hx = drillx::hash(&challenge, &nonce.to_le_bytes()); + let _hx = drillx::hash_with_memory( + &mut memory, + &challenge, + &nonce.to_le_bytes(), + ); // Increment nonce nonce += 1;