2019-03-31 18:54:12 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
2020-01-28 17:03:20 -08:00
|
|
|
use solana_runtime::{
|
|
|
|
accounts::{create_test_accounts, Accounts},
|
|
|
|
bank::*,
|
|
|
|
};
|
|
|
|
use solana_sdk::{account::Account, genesis_config::create_genesis_config, pubkey::Pubkey};
|
2019-12-05 18:41:29 -08:00
|
|
|
use std::{path::PathBuf, sync::Arc};
|
2019-03-31 18:54:12 -07:00
|
|
|
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);
|
2020-06-08 17:38:14 -07:00
|
|
|
pubkeys.push(pubkey);
|
2019-03-31 18:54:12 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 09:11:56 -08:00
|
|
|
#[bench]
|
|
|
|
fn bench_has_duplicates(bencher: &mut Bencher) {
|
|
|
|
bencher.iter(|| {
|
|
|
|
let data = test::black_box([1, 2, 3]);
|
|
|
|
assert!(!Accounts::has_duplicates(&data));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-31 18:54:12 -07:00
|
|
|
#[bench]
|
|
|
|
fn test_accounts_create(bencher: &mut Bencher) {
|
2019-11-08 20:56:57 -08:00
|
|
|
let (genesis_config, _) = create_genesis_config(10_000);
|
2020-03-22 11:10:04 -07:00
|
|
|
let bank0 = Bank::new_with_paths(&genesis_config, vec![PathBuf::from("bench_a0")], &[]);
|
2019-03-31 18:54:12 -07:00
|
|
|
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) {
|
2019-11-08 20:56:57 -08:00
|
|
|
let (genesis_config, _) = create_genesis_config(100_000);
|
2020-05-05 08:33:41 -07:00
|
|
|
let bank1 = Arc::new(Bank::new_with_paths(
|
2019-11-08 20:56:57 -08:00
|
|
|
&genesis_config,
|
2019-12-05 18:41:29 -08:00
|
|
|
vec![PathBuf::from("bench_a1")],
|
2020-03-22 11:10:04 -07:00
|
|
|
&[],
|
2020-05-05 08:33:41 -07:00
|
|
|
));
|
2019-03-31 18:54:12 -07:00
|
|
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
2020-06-08 17:38:14 -07:00
|
|
|
deposit_many(&bank1, &mut pubkeys, 250_000);
|
2020-05-05 08:33:41 -07:00
|
|
|
bank1.freeze();
|
|
|
|
|
|
|
|
// Measures the performance of the squash operation.
|
|
|
|
// This mainly consists of the freeze operation which calculates the
|
|
|
|
// merkle hash of the account state and distribution of fees and rent
|
|
|
|
let mut slot = 1u64;
|
2019-03-31 18:54:12 -07:00
|
|
|
bencher.iter(|| {
|
2020-05-05 08:33:41 -07:00
|
|
|
let bank2 = Arc::new(Bank::new_from_parent(&bank1, &Pubkey::default(), slot));
|
|
|
|
bank2.deposit(&pubkeys[0], 1);
|
|
|
|
bank2.squash();
|
|
|
|
slot += 1;
|
2019-03-31 18:54:12 -07:00
|
|
|
});
|
|
|
|
}
|
2019-07-19 09:32:29 -07:00
|
|
|
|
|
|
|
#[bench]
|
2019-12-19 16:39:30 -08:00
|
|
|
fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
|
2019-12-05 18:41:29 -08:00
|
|
|
let accounts = Accounts::new(vec![PathBuf::from("bench_accounts_hash_internal")]);
|
2019-07-19 09:32:29 -07:00
|
|
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
2019-08-13 16:05:37 -07:00
|
|
|
create_test_accounts(&accounts, &mut pubkeys, 60000, 0);
|
2019-10-18 12:59:47 -07:00
|
|
|
let ancestors = vec![(0, 0)].into_iter().collect();
|
2020-02-22 13:46:40 -08:00
|
|
|
accounts.accounts_db.update_accounts_hash(0, &ancestors);
|
2020-02-21 11:30:00 -08:00
|
|
|
bencher.iter(|| assert!(accounts.verify_bank_hash(0, &ancestors)));
|
2019-07-19 09:32:29 -07:00
|
|
|
}
|
2020-02-22 13:46:40 -08:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn test_update_accounts_hash(bencher: &mut Bencher) {
|
|
|
|
solana_logger::setup();
|
|
|
|
let accounts = Accounts::new(vec![PathBuf::from("update_accounts_hash")]);
|
|
|
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
|
|
|
create_test_accounts(&accounts, &mut pubkeys, 50_000, 0);
|
|
|
|
let ancestors = vec![(0, 0)].into_iter().collect();
|
|
|
|
bencher.iter(|| {
|
|
|
|
accounts.accounts_db.update_accounts_hash(0, &ancestors);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn test_accounts_delta_hash(bencher: &mut Bencher) {
|
|
|
|
solana_logger::setup();
|
|
|
|
let accounts = Accounts::new(vec![PathBuf::from("accounts_delta_hash")]);
|
|
|
|
let mut pubkeys: Vec<Pubkey> = vec![];
|
|
|
|
create_test_accounts(&accounts, &mut pubkeys, 100_000, 0);
|
|
|
|
bencher.iter(|| {
|
|
|
|
accounts.accounts_db.get_accounts_delta_hash(0);
|
|
|
|
});
|
|
|
|
}
|
2020-07-15 06:49:22 -07:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_delete_dependencies(bencher: &mut Bencher) {
|
|
|
|
solana_logger::setup();
|
|
|
|
let accounts = Accounts::new(vec![PathBuf::from("accounts_delete_deps")]);
|
|
|
|
let mut old_pubkey = Pubkey::default();
|
|
|
|
let zero_account = Account::new(0, 0, &Account::default().owner);
|
|
|
|
for i in 0..1000 {
|
|
|
|
let pubkey = Pubkey::new_rand();
|
|
|
|
let account = Account::new((i + 1) as u64, 0, &Account::default().owner);
|
|
|
|
accounts.store_slow(i, &pubkey, &account);
|
|
|
|
accounts.store_slow(i, &old_pubkey, &zero_account);
|
|
|
|
old_pubkey = pubkey;
|
|
|
|
accounts.add_root(i);
|
|
|
|
}
|
|
|
|
bencher.iter(|| {
|
|
|
|
accounts.accounts_db.clean_accounts();
|
|
|
|
});
|
|
|
|
}
|