2019-02-26 03:27:42 +00:00
|
|
|
use criterion::Criterion;
|
2019-02-26 09:25:29 +00:00
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Benchmark};
|
2019-02-26 03:27:42 +00:00
|
|
|
// use env_logger::{Builder, Env};
|
|
|
|
use state_processing::SlotProcessable;
|
2019-02-26 07:18:59 +00:00
|
|
|
use types::beacon_state::BeaconStateBuilder;
|
2019-02-26 09:00:07 +00:00
|
|
|
use types::*;
|
2019-02-26 03:27:42 +00:00
|
|
|
|
|
|
|
fn epoch_processing(c: &mut Criterion) {
|
|
|
|
// Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
|
|
|
2019-02-26 09:25:29 +00:00
|
|
|
let mut builder = BeaconStateBuilder::new(16_384);
|
2019-02-26 03:27:42 +00:00
|
|
|
|
2019-02-26 09:25:29 +00:00
|
|
|
builder.build_fast().unwrap();
|
2019-02-26 03:27:42 +00:00
|
|
|
builder.teleport_to_end_of_epoch(builder.spec.genesis_epoch + 4);
|
|
|
|
|
2019-02-26 09:00:07 +00:00
|
|
|
let mut state = builder.cloned_state();
|
2019-02-26 03:27:42 +00:00
|
|
|
|
2019-02-26 07:18:59 +00:00
|
|
|
// Build all the caches so the following state does _not_ include the cache-building time.
|
2019-02-26 09:00:07 +00:00
|
|
|
state
|
|
|
|
.build_epoch_cache(RelativeEpoch::Previous, &builder.spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
|
|
|
.build_epoch_cache(RelativeEpoch::Current, &builder.spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
|
|
|
.build_epoch_cache(RelativeEpoch::Next, &builder.spec)
|
|
|
|
.unwrap();
|
2019-02-26 07:18:59 +00:00
|
|
|
|
|
|
|
let cached_state = state.clone();
|
|
|
|
|
|
|
|
// Drop all the caches so the following state includes the cache-building time.
|
|
|
|
state.drop_cache(RelativeEpoch::Previous);
|
|
|
|
state.drop_cache(RelativeEpoch::Current);
|
|
|
|
state.drop_cache(RelativeEpoch::Next);
|
|
|
|
|
|
|
|
let cacheless_state = state;
|
|
|
|
|
|
|
|
let spec_a = builder.spec.clone();
|
|
|
|
let spec_b = builder.spec.clone();
|
|
|
|
|
2019-02-26 09:25:29 +00:00
|
|
|
c.bench(
|
|
|
|
"epoch processing",
|
|
|
|
Benchmark::new("with pre-built caches", move |b| {
|
|
|
|
b.iter_with_setup(
|
|
|
|
|| cached_state.clone(),
|
|
|
|
|mut state| black_box(state.per_slot_processing(Hash256::zero(), &spec_a).unwrap()),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
c.bench(
|
|
|
|
"epoch processing",
|
|
|
|
Benchmark::new("without pre-built caches", move |b| {
|
|
|
|
b.iter_with_setup(
|
|
|
|
|| cacheless_state.clone(),
|
|
|
|
|mut state| black_box(state.per_slot_processing(Hash256::zero(), &spec_b).unwrap()),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
2019-02-26 03:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, epoch_processing,);
|
|
|
|
criterion_main!(benches);
|