8cfa36fedd
* Rename `hashing` crate to `eth2_hashing` * Add license, desc to eth2_hashing Cargo.toml * Remove merkle root from eth2 hashing * Remove old benches folder (zombied from old branch) * Add docs to eth2_hashing * Prepare tree_hash for publishing on crates.io * Update deps to use crates.io instead of paths * Update all crates to pull ssz from crates.io * Remove cached_tree_hash, add patches to manifest * Fix compile error in benches * Remove unused code * Fix fake_crypto compile error
61 lines
2.2 KiB
Rust
61 lines
2.2 KiB
Rust
#[macro_use]
|
|
extern crate lazy_static;
|
|
|
|
use criterion::Criterion;
|
|
use criterion::{black_box, criterion_group, criterion_main, Benchmark};
|
|
use types::test_utils::{generate_deterministic_keypairs, TestingBeaconStateBuilder};
|
|
use types::{BeaconState, EthSpec, Keypair, MainnetEthSpec, MinimalEthSpec};
|
|
|
|
lazy_static! {
|
|
static ref KEYPAIRS: Vec<Keypair> = { generate_deterministic_keypairs(300_000) };
|
|
}
|
|
|
|
fn build_state<T: EthSpec>(validator_count: usize) -> BeaconState<T> {
|
|
let (state, _keypairs) = TestingBeaconStateBuilder::from_keypairs(
|
|
KEYPAIRS[0..validator_count].to_vec(),
|
|
&T::default_spec(),
|
|
)
|
|
.build();
|
|
|
|
assert_eq!(state.validators.len(), validator_count);
|
|
assert_eq!(state.balances.len(), validator_count);
|
|
assert!(state.previous_epoch_attestations.is_empty());
|
|
assert!(state.current_epoch_attestations.is_empty());
|
|
assert!(state.eth1_data_votes.is_empty());
|
|
assert!(state.historical_roots.is_empty());
|
|
|
|
state
|
|
}
|
|
|
|
fn bench_suite<T: EthSpec>(c: &mut Criterion, spec_desc: &str, validator_count: usize) {
|
|
let state = build_state::<T>(validator_count);
|
|
|
|
c.bench(
|
|
&format!("{}/{}_validators", spec_desc, validator_count),
|
|
Benchmark::new("genesis_state", move |b| {
|
|
b.iter_batched_ref(
|
|
|| state.clone(),
|
|
// Note: `state.canonical_root()` uses whatever `tree_hash` that the `types` crate
|
|
// uses, which is not necessarily this crate. If you want to ensure that types is
|
|
// using this local version of `tree_hash`, ensure you add a workspace-level
|
|
// [dependency
|
|
// patch](https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section).
|
|
|state| black_box(state.canonical_root()),
|
|
criterion::BatchSize::SmallInput,
|
|
)
|
|
})
|
|
.sample_size(10),
|
|
);
|
|
}
|
|
|
|
fn all_benches(c: &mut Criterion) {
|
|
bench_suite::<MinimalEthSpec>(c, "minimal", 100_000);
|
|
bench_suite::<MinimalEthSpec>(c, "minimal", 300_000);
|
|
|
|
bench_suite::<MainnetEthSpec>(c, "mainnet", 100_000);
|
|
bench_suite::<MainnetEthSpec>(c, "mainnet", 300_000);
|
|
}
|
|
|
|
criterion_group!(benches, all_benches,);
|
|
criterion_main!(benches);
|