2020-09-18 22:03:54 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate solana_core;
|
|
|
|
extern crate test;
|
|
|
|
|
2021-07-20 22:25:13 -07:00
|
|
|
use {
|
|
|
|
solana_core::{
|
2023-06-27 17:25:08 -07:00
|
|
|
consensus::{tower_storage::FileTowerStorage, Tower},
|
|
|
|
vote_simulator::VoteSimulator,
|
2021-07-20 22:25:13 -07:00
|
|
|
},
|
2021-12-03 09:00:31 -08:00
|
|
|
solana_runtime::{bank::Bank, bank_forks::BankForks},
|
2021-07-20 22:25:13 -07:00
|
|
|
solana_sdk::{
|
|
|
|
pubkey::Pubkey,
|
|
|
|
signature::{Keypair, Signer},
|
|
|
|
},
|
|
|
|
std::{
|
|
|
|
collections::{HashMap, HashSet},
|
|
|
|
sync::Arc,
|
|
|
|
},
|
|
|
|
tempfile::TempDir,
|
|
|
|
test::Bencher,
|
|
|
|
trees::tr,
|
2020-09-18 22:03:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_save_tower(bench: &mut Bencher) {
|
|
|
|
let dir = TempDir::new().unwrap();
|
|
|
|
|
|
|
|
let vote_account_pubkey = &Pubkey::default();
|
|
|
|
let node_keypair = Arc::new(Keypair::new());
|
2021-08-05 09:53:29 -07:00
|
|
|
let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank();
|
2021-07-20 22:25:13 -07:00
|
|
|
let tower_storage = FileTowerStorage::new(dir.path().to_path_buf());
|
2020-09-18 22:03:54 -07:00
|
|
|
let tower = Tower::new(
|
|
|
|
&node_keypair.pubkey(),
|
2021-06-18 06:34:46 -07:00
|
|
|
vote_account_pubkey,
|
2020-09-18 22:03:54 -07:00
|
|
|
0,
|
|
|
|
&heaviest_bank,
|
|
|
|
);
|
|
|
|
|
|
|
|
bench.iter(move || {
|
2021-07-20 22:25:13 -07:00
|
|
|
tower.save(&tower_storage, &node_keypair).unwrap();
|
2020-09-18 22:03:54 -07:00
|
|
|
});
|
|
|
|
}
|
2021-07-08 19:07:32 -07:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
#[ignore]
|
|
|
|
fn bench_generate_ancestors_descendants(bench: &mut Bencher) {
|
|
|
|
let vote_account_pubkey = &Pubkey::default();
|
|
|
|
let node_keypair = Arc::new(Keypair::new());
|
2021-08-05 09:53:29 -07:00
|
|
|
let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank();
|
2021-07-08 19:07:32 -07:00
|
|
|
let mut tower = Tower::new(
|
|
|
|
&node_keypair.pubkey(),
|
|
|
|
vote_account_pubkey,
|
|
|
|
0,
|
|
|
|
&heaviest_bank,
|
|
|
|
);
|
|
|
|
|
|
|
|
let num_banks = 500;
|
|
|
|
let forks = tr(0);
|
|
|
|
let mut vote_simulator = VoteSimulator::new(2);
|
2021-08-02 14:33:28 -07:00
|
|
|
vote_simulator.fill_bank_forks(forks, &HashMap::new(), true);
|
2021-07-08 19:07:32 -07:00
|
|
|
vote_simulator.create_and_vote_new_branch(
|
|
|
|
0,
|
|
|
|
num_banks,
|
|
|
|
&HashMap::new(),
|
|
|
|
&HashSet::new(),
|
|
|
|
&Pubkey::new_unique(),
|
|
|
|
&mut tower,
|
|
|
|
);
|
|
|
|
|
|
|
|
bench.iter(move || {
|
|
|
|
for _ in 0..num_banks {
|
|
|
|
let _ancestors = vote_simulator.bank_forks.read().unwrap().ancestors();
|
2022-04-28 11:51:00 -07:00
|
|
|
let _descendants = vote_simulator.bank_forks.read().unwrap().descendants();
|
2021-07-08 19:07:32 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|