Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks for tree_hash_root #26

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ criterion = "0.3"
[[bench]]
name = "rebase"
harness = false

[[bench]]
name = "tree_hash_root"
harness = false
49 changes: 49 additions & 0 deletions benches/tree_hash_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use milhouse::{List, Vector};
use ssz_types::VariableList;
use tree_hash::TreeHash;

type C = typenum::U1099511627776;
type D = typenum::U1000000;
const N: u64 = 1_000_000;

pub fn tree_hash_root(c: &mut Criterion) {
let size = N;

c.bench_with_input(
BenchmarkId::new("tree_hash_root_list", size),
&size,
|b, &size| {
b.iter(|| {
let l1 = List::<u64, C>::try_from_iter(0..size).unwrap();
l1.tree_hash_root()
});
},
);

c.bench_with_input(
BenchmarkId::new("tree_hash_root_vector", size),
&size,
|b, &size| {
b.iter(|| {
let v1 = Vector::<u64, D>::try_from_iter(0..size).unwrap();
v1.tree_hash_root()
});
},
);

// Test `VariableList` as a point of comparison.
c.bench_with_input(
BenchmarkId::new("tree_hash_root_ssz_types_list", size),
&size,
|b, &size| {
b.iter(|| {
let l1 = VariableList::<u64, C>::new((0..size).collect()).unwrap();
l1.tree_hash_root()
})
},
);
}

criterion_group!(benches, tree_hash_root);
criterion_main!(benches);