2019-01-27 04:45:29 +00:00
|
|
|
use criterion::Criterion;
|
2019-02-01 03:48:09 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Benchmark};
|
2019-02-01 07:22:43 +00:00
|
|
|
// use env_logger::{Builder, Env};
|
2019-01-27 04:45:29 +00:00
|
|
|
use test_harness::BeaconChainHarness;
|
2019-02-01 03:48:09 +00:00
|
|
|
use types::{ChainSpec, Hash256};
|
2019-01-27 04:45:29 +00:00
|
|
|
|
|
|
|
fn mid_epoch_state_transition(c: &mut Criterion) {
|
2019-02-01 07:22:43 +00:00
|
|
|
// Builder::from_env(Env::default().default_filter_or("debug")).init();
|
2019-02-01 03:48:09 +00:00
|
|
|
|
|
|
|
let validator_count = 1000;
|
2019-01-27 04:45:29 +00:00
|
|
|
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
let epoch_depth = (rig.spec.epoch_length * 2) + (rig.spec.epoch_length / 2);
|
2019-01-27 04:45:29 +00:00
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
for _ in 0..epoch_depth {
|
2019-01-27 04:45:29 +00:00
|
|
|
rig.advance_chain_with_block();
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
let state = rig.beacon_chain.state.read().clone();
|
|
|
|
|
|
|
|
assert!((state.slot + 1) % rig.spec.epoch_length != 0);
|
2019-01-27 04:45:29 +00:00
|
|
|
|
|
|
|
c.bench_function("mid-epoch state transition 10k validators", move |b| {
|
|
|
|
let state = state.clone();
|
|
|
|
b.iter(|| {
|
2019-02-01 03:48:09 +00:00
|
|
|
let mut state = state.clone();
|
|
|
|
black_box(state.per_slot_processing(Hash256::zero(), &rig.spec))
|
2019-01-27 04:45:29 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn epoch_boundary_state_transition(c: &mut Criterion) {
|
2019-02-01 03:48:09 +00:00
|
|
|
// Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
|
|
|
|
|
|
let validator_count = 10000;
|
2019-01-27 04:45:29 +00:00
|
|
|
let mut rig = BeaconChainHarness::new(ChainSpec::foundation(), validator_count);
|
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
let epoch_depth = rig.spec.epoch_length * 2;
|
2019-01-27 04:45:29 +00:00
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
for _ in 0..(epoch_depth - 1) {
|
2019-01-27 04:45:29 +00:00
|
|
|
rig.advance_chain_with_block();
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:48:09 +00:00
|
|
|
let state = rig.beacon_chain.state.read().clone();
|
|
|
|
|
|
|
|
assert_eq!((state.slot + 1) % rig.spec.epoch_length, 0);
|
|
|
|
|
|
|
|
c.bench(
|
|
|
|
"routines",
|
|
|
|
Benchmark::new("routine_1", move |b| {
|
|
|
|
let state = state.clone();
|
|
|
|
b.iter(|| {
|
|
|
|
let mut state = state.clone();
|
|
|
|
black_box(black_box(
|
|
|
|
state.per_slot_processing(Hash256::zero(), &rig.spec),
|
|
|
|
))
|
|
|
|
})
|
|
|
|
})
|
2019-02-01 07:22:43 +00:00
|
|
|
.sample_size(5), // sample size is low because function is sloooow.
|
2019-01-27 04:45:29 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
benches,
|
2019-02-01 07:22:43 +00:00
|
|
|
mid_epoch_state_transition,
|
2019-01-27 04:45:29 +00:00
|
|
|
epoch_boundary_state_transition
|
|
|
|
);
|
|
|
|
criterion_main!(benches);
|