Move Bank to its own crate
Also: * counters.rs to solana_metrics * genesis_block.rs to solana_sdk
This commit is contained in:
56
runtime/benches/bank.rs
Normal file
56
runtime/benches/bank.rs
Normal file
@ -0,0 +1,56 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
use solana_runtime::bank::*;
|
||||
use solana_runtime::last_id_queue::MAX_ENTRY_IDS;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_process_transaction(bencher: &mut Bencher) {
|
||||
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.
|
||||
let rando0 = Keypair::new();
|
||||
let tx = SystemTransaction::new_move(
|
||||
&mint_keypair,
|
||||
rando0.pubkey(),
|
||||
10_000,
|
||||
bank.last_id(),
|
||||
0,
|
||||
);
|
||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||
|
||||
// Seed the 'to' account and a cell for its signature.
|
||||
let rando1 = Keypair::new();
|
||||
let tx = SystemTransaction::new_move(&rando0, rando1.pubkey(), 1, bank.last_id(), 0);
|
||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||
|
||||
// Finally, return the transaction to the benchmark.
|
||||
tx
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut id = bank.last_id();
|
||||
|
||||
for _ in 0..(MAX_ENTRY_IDS - 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));
|
||||
})
|
||||
}
|
101
runtime/benches/bloom.rs
Normal file
101
runtime/benches/bloom.rs
Normal file
@ -0,0 +1,101 @@
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
use bv::BitVec;
|
||||
use fnv::FnvHasher;
|
||||
use solana_runtime::bloom::{Bloom, BloomHashIndex};
|
||||
use solana_sdk::hash::{hash, Hash};
|
||||
use solana_sdk::signature::Signature;
|
||||
//use std::collections::HashSet;
|
||||
use hashbrown::HashSet;
|
||||
use std::hash::Hasher;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
#[ignore]
|
||||
fn bench_bits_set(bencher: &mut Bencher) {
|
||||
let mut bits: BitVec<u8> = BitVec::new_fill(false, 38_340_234 as u64);
|
||||
let mut hasher = FnvHasher::default();
|
||||
|
||||
bencher.iter(|| {
|
||||
let idx = hasher.finish() % bits.len();
|
||||
bits.set(idx, true);
|
||||
hasher.write_u64(idx);
|
||||
});
|
||||
// subtract the next bencher result from this one to get a number for raw
|
||||
// bits.set()
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[ignore]
|
||||
fn bench_bits_set_hasher(bencher: &mut Bencher) {
|
||||
let bits: BitVec<u8> = BitVec::new_fill(false, 38_340_234 as u64);
|
||||
let mut hasher = FnvHasher::default();
|
||||
|
||||
bencher.iter(|| {
|
||||
let idx = hasher.finish() % bits.len();
|
||||
hasher.write_u64(idx);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[ignore]
|
||||
fn bench_sigs_bloom(bencher: &mut Bencher) {
|
||||
// 1M TPS * 1s (length of block in sigs) == 1M items in filter
|
||||
// 1.0E-8 false positive rate
|
||||
// https://hur.st/bloomfilter/?n=1000000&p=1.0E-8&m=&k=
|
||||
let last_id = hash(Hash::default().as_ref());
|
||||
// eprintln!("last_id = {:?}", last_id);
|
||||
let keys = (0..27)
|
||||
.into_iter()
|
||||
.map(|i| last_id.hash_at_index(i))
|
||||
.collect();
|
||||
let mut sigs: Bloom<Signature> = Bloom::new(38_340_234, keys);
|
||||
|
||||
let mut id = last_id;
|
||||
let mut falses = 0;
|
||||
let mut iterations = 0;
|
||||
bencher.iter(|| {
|
||||
id = hash(id.as_ref());
|
||||
let mut sigbytes = Vec::from(id.as_ref());
|
||||
id = hash(id.as_ref());
|
||||
sigbytes.extend(id.as_ref());
|
||||
|
||||
let sig = Signature::new(&sigbytes);
|
||||
if sigs.contains(&sig) {
|
||||
falses += 1;
|
||||
}
|
||||
sigs.add(&sig);
|
||||
sigs.contains(&sig);
|
||||
iterations += 1;
|
||||
});
|
||||
assert_eq!(falses, 0);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
#[ignore]
|
||||
fn bench_sigs_hashmap(bencher: &mut Bencher) {
|
||||
// same structure as above, new
|
||||
let last_id = hash(Hash::default().as_ref());
|
||||
// eprintln!("last_id = {:?}", last_id);
|
||||
let mut sigs: HashSet<Signature> = HashSet::new();
|
||||
|
||||
let mut id = last_id;
|
||||
let mut falses = 0;
|
||||
let mut iterations = 0;
|
||||
bencher.iter(|| {
|
||||
id = hash(id.as_ref());
|
||||
let mut sigbytes = Vec::from(id.as_ref());
|
||||
id = hash(id.as_ref());
|
||||
sigbytes.extend(id.as_ref());
|
||||
|
||||
let sig = Signature::new(&sigbytes);
|
||||
if sigs.contains(&sig) {
|
||||
falses += 1;
|
||||
}
|
||||
sigs.insert(sig);
|
||||
sigs.contains(&sig);
|
||||
iterations += 1;
|
||||
});
|
||||
assert_eq!(falses, 0);
|
||||
}
|
Reference in New Issue
Block a user