2019-06-10 18:15:39 -07:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
rand::{thread_rng, Rng},
|
2023-08-09 13:03:36 -07:00
|
|
|
solana_accounts_db::{
|
2021-12-11 09:47:05 -08:00
|
|
|
account_info::AccountInfo,
|
2021-12-03 09:00:31 -08:00
|
|
|
accounts_index::{
|
2022-07-07 13:40:17 -07:00
|
|
|
AccountSecondaryIndexes, AccountsIndex, UpsertReclaim,
|
|
|
|
ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS,
|
2021-12-03 09:00:31 -08:00
|
|
|
},
|
2021-08-17 12:50:01 -07:00
|
|
|
},
|
2022-02-23 15:01:23 -08:00
|
|
|
solana_sdk::{account::AccountSharedData, pubkey},
|
2022-09-12 11:51:12 -07:00
|
|
|
std::sync::Arc,
|
2021-12-03 09:00:31 -08:00
|
|
|
test::Bencher,
|
2021-05-10 07:22:48 -07:00
|
|
|
};
|
2019-06-10 18:15:39 -07:00
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_accounts_index(bencher: &mut Bencher) {
|
|
|
|
const NUM_PUBKEYS: usize = 10_000;
|
2020-10-19 12:23:14 -07:00
|
|
|
let pubkeys: Vec<_> = (0..NUM_PUBKEYS).map(|_| pubkey::new_rand()).collect();
|
2019-06-10 18:15:39 -07:00
|
|
|
|
|
|
|
const NUM_FORKS: u64 = 16;
|
|
|
|
|
|
|
|
let mut reclaims = vec![];
|
2023-02-23 13:05:06 -08:00
|
|
|
let index = AccountsIndex::<AccountInfo, AccountInfo>::new(
|
2022-09-12 11:51:12 -07:00
|
|
|
Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
|
2023-05-31 10:36:44 -07:00
|
|
|
Arc::default(),
|
2022-09-12 11:51:12 -07:00
|
|
|
);
|
2019-06-10 18:15:39 -07:00
|
|
|
for f in 0..NUM_FORKS {
|
2020-06-08 17:38:14 -07:00
|
|
|
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
|
2020-12-31 18:06:03 -08:00
|
|
|
index.upsert(
|
2022-02-25 10:58:08 -08:00
|
|
|
f,
|
2020-12-31 18:06:03 -08:00
|
|
|
f,
|
|
|
|
pubkey,
|
2022-02-23 15:01:23 -08:00
|
|
|
&AccountSharedData::default(),
|
2021-05-10 07:22:48 -07:00
|
|
|
&AccountSecondaryIndexes::default(),
|
2020-12-31 18:06:03 -08:00
|
|
|
AccountInfo::default(),
|
|
|
|
&mut reclaims,
|
2022-07-07 13:40:17 -07:00
|
|
|
UpsertReclaim::PopulateReclaims,
|
2020-12-31 18:06:03 -08:00
|
|
|
);
|
2019-06-10 18:15:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut fork = NUM_FORKS;
|
|
|
|
let mut root = 0;
|
|
|
|
bencher.iter(|| {
|
|
|
|
for _p in 0..NUM_PUBKEYS {
|
|
|
|
let pubkey = thread_rng().gen_range(0, NUM_PUBKEYS);
|
2020-10-21 17:05:27 -07:00
|
|
|
index.upsert(
|
2022-02-25 10:58:08 -08:00
|
|
|
fork,
|
2019-06-10 18:15:39 -07:00
|
|
|
fork,
|
|
|
|
&pubkeys[pubkey],
|
2022-02-23 15:01:23 -08:00
|
|
|
&AccountSharedData::default(),
|
2021-05-10 07:22:48 -07:00
|
|
|
&AccountSecondaryIndexes::default(),
|
2019-06-10 18:15:39 -07:00
|
|
|
AccountInfo::default(),
|
|
|
|
&mut reclaims,
|
2022-07-07 13:40:17 -07:00
|
|
|
UpsertReclaim::PopulateReclaims,
|
2019-06-10 18:15:39 -07:00
|
|
|
);
|
|
|
|
reclaims.clear();
|
|
|
|
}
|
2022-12-13 11:26:28 -08:00
|
|
|
index.add_root(root);
|
2019-06-10 18:15:39 -07:00
|
|
|
root += 1;
|
|
|
|
fork += 1;
|
|
|
|
});
|
|
|
|
}
|