Skip to content

Commit

Permalink
use memory and core pinning in benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Aug 8, 2024
1 parent 53cccb7 commit 3f92bda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
26 changes: 22 additions & 4 deletions src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{sync::Arc, time::Instant};

use drillx::equix;
use solana_rpc_client::spinner;

use crate::{args::BenchmarkArgs, Miner};
Expand All @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit 3f92bda

Please sign in to comment.