solana-with-rpc-optimizations/accounts-db/benches/accounts_index.rs

68 lines
1.8 KiB
Rust
Raw Normal View History

#![feature(test)]
extern crate test;
use {
rand::{thread_rng, Rng},
solana_accounts_db::{
account_info::AccountInfo,
accounts_index::{
2022-07-07 13:40:17 -07:00
AccountSecondaryIndexes, AccountsIndex, UpsertReclaim,
ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS,
},
},
solana_sdk::{account::AccountSharedData, pubkey},
std::sync::Arc,
test::Bencher,
};
#[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();
const NUM_FORKS: u64 = 16;
let mut reclaims = vec![];
let index = AccountsIndex::<AccountInfo, AccountInfo>::new(
Some(ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS),
Arc::default(),
);
for f in 0..NUM_FORKS {
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
2020-12-31 18:06:03 -08:00
index.upsert(
f,
2020-12-31 18:06:03 -08:00
f,
pubkey,
&AccountSharedData::default(),
&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
);
}
}
let mut fork = NUM_FORKS;
let mut root = 0;
bencher.iter(|| {
for _p in 0..NUM_PUBKEYS {
Bump rand to 0.8, rand_chacha to 0.3, getrandom to 0.2 (#32871) * sdk: Add concurrent support for rand 0.7 and 0.8 * Update rand, rand_chacha, and getrandom versions * Run command to replace `gen_range` Run `git grep -l gen_range | xargs sed -i'' -e 's/gen_range(\(\S*\), /gen_range(\1../' * sdk: Fix users of older `gen_range` * Replace `hash::new_rand` with `hash::new_with_thread_rng` Run: ``` git grep -l hash::new_rand | xargs sed -i'' -e 's/hash::new_rand([^)]*/hash::new_with_thread_rng(/' ``` * perf: Use `Keypair::new()` instead of `generate` * Use older rand version in zk-token-sdk * program-runtime: Inline random key generation * bloom: Fix clippy warnings in tests * streamer: Scope rng usage correctly * perf: Fix clippy warning * accounts-db: Map to char to generate a random string * Remove `from_secret_key_bytes`, it's just `keypair_from_seed` * ledger: Generate keypairs by hand * ed25519-tests: Use new rand * runtime: Use new rand in all tests * gossip: Clean up clippy and inline keypair generators * core: Inline keypair generation for tests * Push sbf lockfile change * sdk: Sort dependencies correctly * Remove `hash::new_with_thread_rng`, use `Hash::new_unique()` * Use Keypair::new where chacha isn't used * sdk: Fix build by marking rand 0.7 optional * Hardcode secret key length, add static assertion * Unify `getrandom` crate usage to fix linking errors * bloom: Fix tests that require a random hash * Remove some dependencies, try to unify others * Remove unnecessary uses of rand and rand_core * Update lockfiles * Add back some dependencies to reduce rebuilds * Increase max rebuilds from 14 to 15 * frozen-abi: Remove `getrandom` * Bump rebuilds to 17 * Remove getrandom from zk-token-proof
2023-08-21 10:11:21 -07:00
let pubkey = thread_rng().gen_range(0..NUM_PUBKEYS);
index.upsert(
fork,
fork,
&pubkeys[pubkey],
&AccountSharedData::default(),
&AccountSecondaryIndexes::default(),
AccountInfo::default(),
&mut reclaims,
2022-07-07 13:40:17 -07:00
UpsertReclaim::PopulateReclaims,
);
reclaims.clear();
}
index.add_root(root);
root += 1;
fork += 1;
});
}