Add benches for shredding and poh (#6307)

* Add benches for shredding and poh

* ignore poh bench

* Factor out Poh bench as separate function
This commit is contained in:
carllin
2019-10-10 14:00:24 -07:00
committed by GitHub
parent 1b775044f7
commit 1960ea8ed7
3 changed files with 69 additions and 29 deletions

View File

@ -1,5 +1,7 @@
//! The `Poh` module provides an object for generating a Proof of History.
use solana_sdk::hash::{hash, hashv, Hash};
use std::thread::{Builder, JoinHandle};
use std::time::{Duration, Instant};
pub struct Poh {
pub hash: Hash,
@ -80,6 +82,37 @@ impl Poh {
}
}
pub fn compute_hashes_per_tick(duration: Duration, hashes_sample_size: u64) -> u64 {
let num_cpu = sys_info::cpu_num().unwrap();
// calculate hash rate with the system under maximum load
info!(
"Running {} hashes in parallel on all threads...",
hashes_sample_size
);
let threads: Vec<JoinHandle<u64>> = (0..num_cpu)
.map(|_| {
Builder::new()
.name("solana-poh".to_string())
.spawn(move || {
let mut v = Hash::default();
let start = Instant::now();
for _ in 0..hashes_sample_size {
v = hash(&v.as_ref());
}
start.elapsed().as_millis() as u64
})
.unwrap()
})
.collect();
let avg_elapsed = (threads
.into_iter()
.map(|elapsed| elapsed.join().unwrap())
.sum::<u64>())
/ u64::from(num_cpu);
duration.as_millis() as u64 * hashes_sample_size / avg_elapsed
}
#[cfg(test)]
mod tests {
use crate::poh::{Poh, PohEntry};