Update benchmark to avoid write locks in sig duplicate detection

This commit is contained in:
Greg Fitzgerald 2018-04-04 17:29:22 -06:00
parent 3cfb07ea38
commit 8d425e127b
1 changed files with 10 additions and 5 deletions

View File

@ -344,6 +344,8 @@ mod bench {
use accountant::*;
use rayon::prelude::*;
use signature::KeyPairUtil;
use hash::hash;
use bincode::serialize;
#[bench]
fn process_verified_event_bench(bencher: &mut Bencher) {
@ -352,24 +354,27 @@ mod bench {
// Create transactions between unrelated parties.
let transactions: Vec<_> = (0..4096)
.into_par_iter()
.map(|_| {
.map(|i| {
// Seed the 'from' account.
let rando0 = KeyPair::new();
let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, mint.last_id());
acc.process_verified_transaction(&tr).unwrap();
// Seed the 'to' account.
// Seed the 'to' account and a cell for its signature.
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
let rando1 = KeyPair::new();
let tr = Transaction::new(&rando0, rando1.pubkey(), 1, mint.last_id());
let tr = Transaction::new(&rando0, rando1.pubkey(), 1, last_id);
acc.process_verified_transaction(&tr).unwrap();
// Finally, return a transaction that's unique
Transaction::new(&rando0, rando1.pubkey(), 1, mint.last_id())
Transaction::new(&rando0, rando1.pubkey(), 1, last_id)
})
.collect();
bencher.iter(|| {
// Since benchmarker runs this multiple times, we need to clear the signatures.
acc.last_ids.write().unwrap().clear();
for (_, sigs) in acc.last_ids.read().unwrap().iter() {
sigs.write().unwrap().clear();
}
transactions.par_iter().for_each(|tr| {
acc.process_verified_transaction(tr).unwrap();