solana/benches/bank.rs

58 lines
1.7 KiB
Rust
Raw Normal View History

#![feature(test)]
extern crate bincode;
extern crate rayon;
extern crate solana;
extern crate test;
use solana::bank::*;
use solana::hash::hash;
use solana::mint::Mint;
2018-08-09 07:56:04 -07:00
use solana::signature::{Keypair, KeypairUtil};
2018-09-26 17:21:43 -07:00
use solana::system_transaction::SystemTransaction;
use solana::transaction::Transaction;
use test::Bencher;
#[bench]
fn bench_process_transaction(bencher: &mut Bencher) {
let mint = Mint::new(100_000_000);
let bank = Bank::new(&mint);
// 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();
2018-09-26 17:21:43 -07:00
let tx = Transaction::system_move(
&mint.keypair(),
rando0.pubkey(),
10_000,
bank.last_id(),
2018-09-26 17:21:43 -07:00
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();
let tx = Transaction::system_move(&rando0, rando1.pubkey(), 1, bank.last_id(), 0);
assert_eq!(bank.process_transaction(&tx), Ok(()));
2018-07-10 15:59:31 -07:00
// Finally, return the transaction to the benchmark.
tx
2018-09-14 16:25:14 -07:00
}).collect();
let mut id = bank.last_id();
for _ in 0..(MAX_ENTRY_IDS - 1) {
bank.register_entry_id(&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
}