solana/runtime/benches/accounts.rs

59 lines
1.9 KiB
Rust
Raw Normal View History

2019-03-31 18:54:12 -07:00
#![feature(test)]
extern crate test;
use solana_runtime::bank::*;
use solana_sdk::account::Account;
use solana_sdk::genesis_block::create_genesis_block;
2019-03-31 18:54:12 -07:00
use solana_sdk::pubkey::Pubkey;
use std::sync::Arc;
use test::Bencher;
2019-03-31 21:31:19 -07:00
fn deposit_many(bank: &Bank, pubkeys: &mut Vec<Pubkey>, num: usize) {
2019-03-31 18:54:12 -07:00
for t in 0..num {
2019-03-31 21:31:19 -07:00
let pubkey = Pubkey::new_rand();
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);
2019-03-31 18:54:12 -07:00
pubkeys.push(pubkey.clone());
assert!(bank.get_account(&pubkey).is_none());
bank.deposit(&pubkey, (t + 1) as u64);
2019-03-31 21:31:19 -07:00
assert_eq!(bank.get_account(&pubkey).unwrap(), account);
2019-03-31 18:54:12 -07:00
}
}
#[bench]
fn test_accounts_create(bencher: &mut Bencher) {
let (genesis_block, _) = create_genesis_block(10_000);
2019-03-31 18:54:12 -07:00
let bank0 = Bank::new_with_paths(&genesis_block, Some("bench_a0".to_string()));
bencher.iter(|| {
let mut pubkeys: Vec<Pubkey> = vec![];
2019-03-31 21:31:19 -07:00
deposit_many(&bank0, &mut pubkeys, 1000);
2019-03-31 18:54:12 -07:00
});
}
#[bench]
fn test_accounts_squash(bencher: &mut Bencher) {
let (genesis_block, _) = create_genesis_block(100_000);
2019-03-31 21:31:19 -07:00
let mut banks: Vec<Arc<Bank>> = Vec::with_capacity(10);
2019-03-31 18:54:12 -07:00
banks.push(Arc::new(Bank::new_with_paths(
&genesis_block,
Some("bench_a1".to_string()),
)));
let mut pubkeys: Vec<Pubkey> = vec![];
2019-03-31 21:31:19 -07:00
deposit_many(&banks[0], &mut pubkeys, 250000);
2019-03-31 18:54:12 -07:00
banks[0].freeze();
2019-03-31 21:31:19 -07:00
// Measures the performance of the squash operation merging the accounts
// with the majority of the accounts present in the parent bank that is
// moved over to this bank.
2019-03-31 18:54:12 -07:00
bencher.iter(|| {
2019-03-31 21:31:19 -07:00
banks.push(Arc::new(Bank::new_from_parent(
&banks[0],
&Pubkey::default(),
1u64,
)));
for accounts in 0..10000 {
banks[1].deposit(&pubkeys[accounts], (accounts + 1) as u64);
2019-03-31 18:54:12 -07:00
}
2019-03-31 21:31:19 -07:00
banks[1].squash();
2019-03-31 18:54:12 -07:00
});
}