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:
Trent Nelson 2019-07-19 10:32:29 -06:00 committed by GitHub
parent 8b69998379
commit 111d0eb89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View File

@ -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<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 60000);
bencher.iter(|| {
accounts.hash_internal_state(0);
});
}

View File

@ -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)]
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<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) {
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<Pubkey> = vec![];
create_accounts(&accounts, &mut pubkeys, 100);
create_test_accounts(&accounts, &mut pubkeys, 100);
check_accounts(&accounts, &pubkeys, 100);
accounts.add_root(0);

View File

@ -1,4 +1,4 @@
mod accounts;
pub mod accounts;
pub mod accounts_db;
pub mod accounts_index;
pub mod append_vec;