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

feat: add hash_tree_root() bench #168

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions ssz-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ snap = "1.0"
project-root = "0.2.2"
serde_json = "1.0.81"
hex = "0.4.3"
criterion = { version = "0.5", features = ["html_reports"] }

[build-dependencies]
sha2 = "0.9.8"

[[bench]]
name = "merkleization"
harness = false
25 changes: 25 additions & 0 deletions ssz-rs/benches/merkleization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use criterion::{criterion_group, criterion_main, Criterion};
use std::hint::black_box;

fn bench_merkleization(c: &mut Criterion) {
use ssz_rs::{HashTreeRoot, List};

let inner: Vec<List<u8, 1073741824>> = vec![
vec![0u8, 1u8, 2u8].try_into().unwrap(),
vec![3u8, 4u8, 5u8].try_into().unwrap(),
vec![6u8, 7u8, 8u8].try_into().unwrap(),
vec![9u8, 10u8, 11u8].try_into().unwrap(),
];

// Emulate a transactions tree
let outer: List<List<u8, 1073741824>, 1048576> = List::try_from(inner).unwrap();

c.bench_function("hash_tree_root", |b| {
b.iter(|| {
let _ = black_box(outer.hash_tree_root().unwrap());
})
});
}

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