2019-05-30 21:31:35 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
bincode::serialize,
|
|
|
|
solana_runtime::status_cache::*,
|
|
|
|
solana_sdk::{
|
|
|
|
hash::{hash, Hash},
|
|
|
|
signature::Signature,
|
|
|
|
},
|
|
|
|
test::Bencher,
|
2020-01-28 17:03:20 -08:00
|
|
|
};
|
2019-05-30 21:31:35 -07:00
|
|
|
|
2021-04-13 14:28:08 +08:00
|
|
|
type BankStatusCache = StatusCache<()>;
|
2019-05-30 21:31:35 -07:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn test_statuscache_serialize(bencher: &mut Bencher) {
|
|
|
|
let mut status_cache = BankStatusCache::default();
|
|
|
|
status_cache.add_root(0);
|
2021-03-28 19:10:14 -07:00
|
|
|
status_cache.clear();
|
2019-05-30 21:31:35 -07:00
|
|
|
for hash_index in 0..100 {
|
|
|
|
let blockhash = Hash::new(&vec![hash_index; std::mem::size_of::<Hash>()]);
|
|
|
|
let mut id = blockhash;
|
|
|
|
for _ in 0..100 {
|
|
|
|
id = hash(id.as_ref());
|
|
|
|
let mut sigbytes = Vec::from(id.as_ref());
|
|
|
|
id = hash(id.as_ref());
|
|
|
|
sigbytes.extend(id.as_ref());
|
|
|
|
let sig = Signature::new(&sigbytes);
|
|
|
|
status_cache.insert(&blockhash, &sig, 0, ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bencher.iter(|| {
|
2020-06-09 01:38:14 +01:00
|
|
|
let _ = serialize(&status_cache.slot_deltas(&[0])).unwrap();
|
2019-05-30 21:31:35 -07:00
|
|
|
});
|
|
|
|
}
|