2018-08-22 07:57:07 -07:00
|
|
|
#![feature(test)]
|
2018-07-10 14:19:42 -07:00
|
|
|
extern crate bincode;
|
|
|
|
extern crate rayon;
|
|
|
|
extern crate solana;
|
2018-11-16 08:04:46 -08:00
|
|
|
extern crate solana_sdk;
|
2018-08-22 07:57:07 -07:00
|
|
|
extern crate test;
|
2018-07-10 14:19:42 -07:00
|
|
|
|
|
|
|
use solana::bank::*;
|
|
|
|
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;
|
2018-11-16 08:04:46 -08:00
|
|
|
use solana_sdk::hash::hash;
|
2018-11-29 16:18:47 -08:00
|
|
|
use solana_sdk::transaction::Transaction;
|
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) {
|
|
|
|
let mint = Mint::new(100_000_000);
|
|
|
|
let bank = Bank::new(&mint);
|
|
|
|
|
|
|
|
// 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();
|
2018-09-26 17:21:43 -07:00
|
|
|
let tx = Transaction::system_move(
|
|
|
|
&mint.keypair(),
|
|
|
|
rando0.pubkey(),
|
|
|
|
10_000,
|
2018-10-10 17:23:06 -07:00
|
|
|
bank.last_id(),
|
2018-09-26 17:21:43 -07: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();
|
2018-10-10 17:23:06 -07:00
|
|
|
let tx = Transaction::system_move(&rando0, rando1.pubkey(), 1, bank.last_id(), 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-09-14 16:25:14 -07:00
|
|
|
}).collect();
|
2018-07-10 14:19:42 -07:00
|
|
|
|
2018-10-17 16:28:26 -07:00
|
|
|
let mut id = bank.last_id();
|
|
|
|
|
|
|
|
for _ in 0..(MAX_ENTRY_IDS - 1) {
|
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
|
|
|
}
|