2018-08-22 07:57:07 -07:00
|
|
|
#![feature(test)]
|
2018-12-08 21:44:20 -08:00
|
|
|
|
2018-08-22 07:57:07 -07:00
|
|
|
extern crate test;
|
2018-07-10 14:19:42 -07:00
|
|
|
|
2019-02-18 22:26:22 -08:00
|
|
|
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-02 16:35:13 -08:00
|
|
|
use solana_sdk::timing::{DEFAULT_TICKS_PER_SLOT, MAX_RECENT_BLOCKHASHES};
|
2018-08-22 07:57:07 -07:00
|
|
|
use test::Bencher;
|
2018-07-10 14:19:42 -07:00
|
|
|
|
2018-08-22 07:57:07 -07:00
|
|
|
#[bench]
|
2018-07-10 14:19:42 -07:00
|
|
|
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);
|
2018-07-10 14:19:42 -07:00
|
|
|
|
|
|
|
// Create transactions between unrelated parties.
|
|
|
|
let transactions: Vec<_> = (0..4096)
|
2018-10-04 13:15:54 -07:00
|
|
|
.into_iter()
|
2018-10-12 15:20:53 -07:00
|
|
|
.map(|_| {
|
2018-07-10 14:19:42 -07:00
|
|
|
// Seed the 'from' account.
|
2018-08-09 07:56:04 -07:00
|
|
|
let rando0 = Keypair::new();
|
2019-02-01 07:36:35 -08:00
|
|
|
let tx = SystemTransaction::new_move(
|
|
|
|
&mint_keypair,
|
2019-03-25 13:10:56 -07:00
|
|
|
&rando0.pubkey(),
|
2019-02-01 07:36:35 -08:00
|
|
|
10_000,
|
2019-03-02 10:25:16 -08:00
|
|
|
bank.last_blockhash(),
|
2019-02-01 07:36:35 -08:00
|
|
|
0,
|
|
|
|
);
|
2018-10-04 13:15:54 -07:00
|
|
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
2018-07-10 14:19:42 -07:00
|
|
|
|
|
|
|
// 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-25 13:10:56 -07:00
|
|
|
SystemTransaction::new_move(&rando0, &rando1.pubkey(), 1, bank.last_blockhash(), 0);
|
2018-10-04 13:15:54 -07:00
|
|
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
2018-07-10 14:19:42 -07:00
|
|
|
|
2018-07-10 15:59:31 -07:00
|
|
|
// Finally, return the transaction to the benchmark.
|
2018-07-10 14:19:42 -07:00
|
|
|
tx
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.collect();
|
2018-07-10 14:19:42 -07:00
|
|
|
|
2019-03-02 10:25:16 -08:00
|
|
|
let mut id = bank.last_blockhash();
|
2018-10-17 16:28:26 -07:00
|
|
|
|
2019-03-02 16:35:13 -08:00
|
|
|
for _ in 0..(MAX_RECENT_BLOCKHASHES * DEFAULT_TICKS_PER_SLOT as usize) {
|
2018-11-05 09:47:41 -08:00
|
|
|
bank.register_tick(&id);
|
2018-10-17 16:28:26 -07:00
|
|
|
id = hash(&id.as_ref())
|
|
|
|
}
|
|
|
|
|
2018-08-22 07:57:07 -07:00
|
|
|
bencher.iter(|| {
|
|
|
|
// Since benchmarker runs this multiple times, we need to clear the signatures.
|
|
|
|
bank.clear_signatures();
|
2018-09-26 05:52:13 -07:00
|
|
|
let results = bank.process_transactions(&transactions);
|
2018-08-22 07:57:07 -07:00
|
|
|
assert!(results.iter().all(Result::is_ok));
|
|
|
|
})
|
2018-07-10 15:30:56 -07:00
|
|
|
}
|