runtime: Add bench for accounts::hash_internal_state (#5157)
* runtime: Add bench for accounts::hash_internal_state * fixup! cargo fmt * fixup! cargo clippy * fixup! Use a more representitive number of accounts * fixup! More descriptive name for accounts creation helper
This commit is contained in:
parent
8b69998379
commit
111d0eb89b
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
|
use solana_runtime::accounts::{create_test_accounts, Accounts};
|
||||||
use solana_runtime::bank::*;
|
use solana_runtime::bank::*;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::genesis_block::create_genesis_block;
|
use solana_sdk::genesis_block::create_genesis_block;
|
||||||
|
@ -56,3 +57,13 @@ fn test_accounts_squash(bencher: &mut Bencher) {
|
||||||
banks[1].squash();
|
banks[1].squash();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn test_accounts_hash_internal_state(bencher: &mut Bencher) {
|
||||||
|
let accounts = Accounts::new(Some("bench_accounts_hash_internal".to_string()));
|
||||||
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||||
|
create_test_accounts(&accounts, &mut pubkeys, 60000);
|
||||||
|
bencher.iter(|| {
|
||||||
|
accounts.hash_internal_state(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -690,6 +690,15 @@ impl Accounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_test_accounts(accounts: &Accounts, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
||||||
|
for t in 0..num {
|
||||||
|
let pubkey = Pubkey::new_rand();
|
||||||
|
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
|
||||||
|
accounts.store_slow(0, &pubkey, &account);
|
||||||
|
pubkeys.push(pubkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// TODO: all the bank tests are bank specific, issue: 2194
|
// TODO: all the bank tests are bank specific, issue: 2194
|
||||||
|
@ -1194,15 +1203,6 @@ mod tests {
|
||||||
assert_eq!(accounts.hash_internal_state(0), None);
|
assert_eq!(accounts.hash_internal_state(0), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_accounts(accounts: &Accounts, pubkeys: &mut Vec<Pubkey>, num: usize) {
|
|
||||||
for t in 0..num {
|
|
||||||
let pubkey = Pubkey::new_rand();
|
|
||||||
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
|
|
||||||
accounts.store_slow(0, &pubkey, &account);
|
|
||||||
pubkeys.push(pubkey.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_accounts(accounts: &Accounts, pubkeys: &Vec<Pubkey>, num: usize) {
|
fn check_accounts(accounts: &Accounts, pubkeys: &Vec<Pubkey>, num: usize) {
|
||||||
for _ in 1..num {
|
for _ in 1..num {
|
||||||
let idx = thread_rng().gen_range(0, num - 1);
|
let idx = thread_rng().gen_range(0, num - 1);
|
||||||
|
@ -1219,7 +1219,7 @@ mod tests {
|
||||||
let accounts = Accounts::new(Some("serialize_accounts".to_string()));
|
let accounts = Accounts::new(Some("serialize_accounts".to_string()));
|
||||||
|
|
||||||
let mut pubkeys: Vec<Pubkey> = vec![];
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
||||||
create_accounts(&accounts, &mut pubkeys, 100);
|
create_test_accounts(&accounts, &mut pubkeys, 100);
|
||||||
check_accounts(&accounts, &pubkeys, 100);
|
check_accounts(&accounts, &pubkeys, 100);
|
||||||
accounts.add_root(0);
|
accounts.add_root(0);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
mod accounts;
|
pub mod accounts;
|
||||||
pub mod accounts_db;
|
pub mod accounts_db;
|
||||||
pub mod accounts_index;
|
pub mod accounts_index;
|
||||||
pub mod append_vec;
|
pub mod append_vec;
|
||||||
|
|
Loading…
Reference in New Issue