uses rust intrinsics to convert hashes to u64 (#12097)

This commit is contained in:
behzad nouri
2020-09-09 15:28:17 +00:00
committed by GitHub
parent 697e004e0d
commit 28f2fa3fd5
3 changed files with 57 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
#![feature(test)]
extern crate test;
use rand::{thread_rng, Rng};
use solana_core::crds_gossip_pull::CrdsFilter;
use solana_sdk::hash::{Hash, HASH_BYTES};
use test::Bencher;
#[bench]
fn bench_hash_as_u64(bencher: &mut Bencher) {
let mut rng = thread_rng();
let hashes: Vec<_> = (0..1000)
.map(|_| {
let mut buf = [0u8; HASH_BYTES];
rng.fill(&mut buf);
Hash::new(&buf)
})
.collect();
bencher.iter(|| {
hashes
.iter()
.map(CrdsFilter::hash_as_u64)
.collect::<Vec<_>>()
});
}