solana/runtime/benches/bank.rs

58 lines
1.8 KiB
Rust
Raw Normal View History

#![feature(test)]
extern crate test;
use solana_runtime::bank::*;
use solana_sdk::genesis_block::GenesisBlock;
2018-11-16 08:04:46 -08:00
use solana_sdk::hash::hash;
2018-12-03 10:26:28 -08:00
use solana_sdk::signature::{Keypair, KeypairUtil};
2018-12-04 15:37:11 -08:00
use solana_sdk::system_transaction::SystemTransaction;
2019-03-01 12:16:20 -08:00
use solana_sdk::timing::MAX_RECENT_TICK_HASHES;
use test::Bencher;
#[bench]
fn bench_process_transaction(bencher: &mut Bencher) {
2019-01-24 12:04:04 -08:00
let (genesis_block, mint_keypair) = GenesisBlock::new(100_000_000);
let bank = Bank::new(&genesis_block);
// Create transactions between unrelated parties.
let transactions: Vec<_> = (0..4096)
.into_iter()
.map(|_| {
// Seed the 'from' account.
2018-08-09 07:56:04 -07:00
let rando0 = Keypair::new();
let tx = SystemTransaction::new_move(
&mint_keypair,
rando0.pubkey(),
10_000,
2019-03-02 10:25:16 -08:00
bank.last_blockhash(),
0,
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
// Seed the 'to' account and a cell for its signature.
2018-08-09 07:56:04 -07:00
let rando1 = Keypair::new();
2019-03-02 10:20:10 -08:00
let tx =
2019-03-02 10:25:16 -08:00
SystemTransaction::new_move(&rando0, rando1.pubkey(), 1, bank.last_blockhash(), 0);
assert_eq!(bank.process_transaction(&tx), Ok(()));
2018-07-10 15:59:31 -07:00
// Finally, return the transaction to the benchmark.
tx
})
.collect();
2019-03-02 10:25:16 -08:00
let mut id = bank.last_blockhash();
2019-03-01 12:16:20 -08:00
for _ in 0..(MAX_RECENT_TICK_HASHES - 1) {
bank.register_tick(&id);
id = hash(&id.as_ref())
}
bencher.iter(|| {
// Since benchmarker runs this multiple times, we need to clear the signatures.
bank.clear_signatures();
let results = bank.process_transactions(&transactions);
assert!(results.iter().all(Result::is_ok));
})
2018-07-10 15:30:56 -07:00
}