mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 13:54:44 +00:00
Tree hash benches (#486)
* Add initial tree hash benches * Add tree hash example * Use lazy static in tree hash benches
This commit is contained in:
35
eth2/utils/tree_hash/examples/flamegraph_beacon_state.rs
Normal file
35
eth2/utils/tree_hash/examples/flamegraph_beacon_state.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use tree_hash::TreeHash;
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use types::{BeaconState, EthSpec, MainnetEthSpec};
|
||||
|
||||
const TREE_HASH_LOOPS: usize = 1_000;
|
||||
const VALIDATOR_COUNT: usize = 1_000;
|
||||
|
||||
fn build_state<T: EthSpec>(validator_count: usize) -> BeaconState<T> {
|
||||
let (state, _keypairs) = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(
|
||||
validator_count,
|
||||
&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 main() {
|
||||
let state = build_state::<MainnetEthSpec>(VALIDATOR_COUNT);
|
||||
|
||||
// This vec is an attempt to ensure the compiler doesn't optimize-out the hashing.
|
||||
let mut vec = Vec::with_capacity(TREE_HASH_LOOPS);
|
||||
|
||||
for _ in 0..TREE_HASH_LOOPS {
|
||||
let root = state.tree_hash_root();
|
||||
vec.push(root[0]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user