2019-03-09 03:11:49 +00:00
|
|
|
use criterion::Criterion;
|
|
|
|
use criterion::{black_box, Benchmark};
|
2019-03-10 07:31:14 +00:00
|
|
|
use ssz::TreeHash;
|
2019-03-09 03:11:49 +00:00
|
|
|
use state_processing::{
|
|
|
|
per_block_processing,
|
|
|
|
per_block_processing::{
|
|
|
|
process_attestations, process_attester_slashings, process_deposits, process_eth1_data,
|
|
|
|
process_exits, process_proposer_slashings, process_randao, process_transfers,
|
|
|
|
verify_block_signature,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
use types::*;
|
|
|
|
|
|
|
|
/// Run the detailed benchmarking suite on the given `BeaconState`.
|
|
|
|
///
|
|
|
|
/// `desc` will be added to the title of each bench.
|
2019-03-14 05:44:56 +00:00
|
|
|
pub fn bench_block_processing(
|
2019-03-09 03:11:49 +00:00
|
|
|
c: &mut Criterion,
|
|
|
|
initial_block: &BeaconBlock,
|
|
|
|
initial_state: &BeaconState,
|
|
|
|
initial_spec: &ChainSpec,
|
|
|
|
desc: &str,
|
|
|
|
) {
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("verify_block_signature", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
2019-03-10 23:56:31 +00:00
|
|
|
|mut state| {
|
|
|
|
verify_block_signature(&mut state, &block, &spec).unwrap();
|
|
|
|
state
|
|
|
|
},
|
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_randao", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
2019-03-10 23:56:31 +00:00
|
|
|
|mut state| {
|
|
|
|
process_randao(&mut state, &block, &spec).unwrap();
|
|
|
|
state
|
|
|
|
},
|
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_eth1_data", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
2019-03-10 23:56:31 +00:00
|
|
|
|mut state| {
|
|
|
|
process_eth1_data(&mut state, &block.eth1_data).unwrap();
|
|
|
|
state
|
|
|
|
},
|
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_proposer_slashings", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_proposer_slashings(&mut state, &block.body.proposer_slashings, &spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_attester_slashings", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_attester_slashings(&mut state, &block.body.attester_slashings, &spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
2019-03-09 21:30:36 +00:00
|
|
|
let block = initial_block.clone();
|
2019-03-09 03:11:49 +00:00
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_attestations", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_attestations(&mut state, &block.body.attestations, &spec).unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_deposits", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_deposits(&mut state, &block.body.deposits, &spec).unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_exits", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_exits(&mut state, &block.body.voluntary_exits, &spec).unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
|
|
|
let block = initial_block.clone();
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("process_transfers", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
process_transfers(&mut state, &block.body.transfers, &spec).unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state = initial_state.clone();
|
2019-03-09 21:30:36 +00:00
|
|
|
let block = initial_block.clone();
|
2019-03-09 03:11:49 +00:00
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 21:30:36 +00:00
|
|
|
Benchmark::new("per_block_processing", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
2019-03-10 23:56:31 +00:00
|
|
|
|mut state| {
|
|
|
|
per_block_processing(&mut state, &block, &spec).unwrap();
|
|
|
|
state
|
|
|
|
},
|
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut state = initial_state.clone();
|
|
|
|
state.drop_cache(RelativeEpoch::Previous);
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("build_previous_state_epoch_cache", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
state
|
|
|
|
.build_epoch_cache(RelativeEpoch::Previous, &spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut state = initial_state.clone();
|
|
|
|
state.drop_cache(RelativeEpoch::Current);
|
|
|
|
let spec = initial_spec.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-09 03:11:49 +00:00
|
|
|
Benchmark::new("build_current_state_epoch_cache", move |b| {
|
2019-03-10 23:56:31 +00:00
|
|
|
b.iter_batched(
|
2019-03-09 03:11:49 +00:00
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
2019-03-10 23:56:31 +00:00
|
|
|
state
|
|
|
|
.build_epoch_cache(RelativeEpoch::Current, &spec)
|
|
|
|
.unwrap();
|
|
|
|
state
|
2019-03-09 03:11:49 +00:00
|
|
|
},
|
2019-03-10 23:56:31 +00:00
|
|
|
criterion::BatchSize::SmallInput,
|
2019-03-09 03:11:49 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
2019-03-10 07:31:14 +00:00
|
|
|
|
2019-03-13 05:49:32 +00:00
|
|
|
let mut state = initial_state.clone();
|
|
|
|
state.drop_pubkey_cache();
|
|
|
|
c.bench(
|
|
|
|
&format!("{}/block_processing", desc),
|
|
|
|
Benchmark::new("build_pubkey_cache", move |b| {
|
|
|
|
b.iter_batched(
|
|
|
|
|| state.clone(),
|
|
|
|
|mut state| {
|
|
|
|
state.update_pubkey_cache().unwrap();
|
|
|
|
state
|
|
|
|
},
|
|
|
|
criterion::BatchSize::SmallInput,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
|
|
|
|
2019-03-10 07:31:14 +00:00
|
|
|
let block = initial_block.clone();
|
|
|
|
c.bench(
|
2019-03-11 03:52:21 +00:00
|
|
|
&format!("{}/block_processing", desc),
|
2019-03-10 07:31:14 +00:00
|
|
|
Benchmark::new("tree_hash_block", move |b| {
|
|
|
|
b.iter(|| black_box(block.hash_tree_root()))
|
|
|
|
})
|
|
|
|
.sample_size(10),
|
|
|
|
);
|
2019-03-09 03:11:49 +00:00
|
|
|
}
|