diff --git a/runtime/benches/accounts.rs b/runtime/benches/accounts.rs index 29f9bf7c53..8350e1a04e 100644 --- a/runtime/benches/accounts.rs +++ b/runtime/benches/accounts.rs @@ -2,6 +2,7 @@ extern crate test; +use solana_runtime::accounts::{create_test_accounts, Accounts}; use solana_runtime::bank::*; use solana_sdk::account::Account; use solana_sdk::genesis_block::create_genesis_block; @@ -56,3 +57,13 @@ fn test_accounts_squash(bencher: &mut Bencher) { 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 = vec![]; + create_test_accounts(&accounts, &mut pubkeys, 60000); + bencher.iter(|| { + accounts.hash_internal_state(0); + }); +} diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 5033e79d1b..dc39fba24e 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -690,6 +690,15 @@ impl Accounts { } } +pub fn create_test_accounts(accounts: &Accounts, pubkeys: &mut Vec, 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)] mod tests { // TODO: all the bank tests are bank specific, issue: 2194 @@ -1194,15 +1203,6 @@ mod tests { assert_eq!(accounts.hash_internal_state(0), None); } - fn create_accounts(accounts: &Accounts, pubkeys: &mut Vec, 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, num: usize) { for _ in 1..num { 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 mut pubkeys: Vec = vec![]; - create_accounts(&accounts, &mut pubkeys, 100); + create_test_accounts(&accounts, &mut pubkeys, 100); check_accounts(&accounts, &pubkeys, 100); accounts.add_root(0); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 56b185e019..3642fa6b88 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,4 +1,4 @@ -mod accounts; +pub mod accounts; pub mod accounts_db; pub mod accounts_index; pub mod append_vec;