Skip to content

Commit

Permalink
Add roothash benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmichalis committed Dec 18, 2024
1 parent 171d8fc commit e584c4e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/rbuilder/benches/bench_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ mod benchmarks;
criterion_main! {
benchmarks::mev_boost::serialization,
benchmarks::txpool_fetcher::txpool,
benchmarks::roothash::roothash,
}
1 change: 1 addition & 0 deletions crates/rbuilder/benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod mev_boost;
pub mod roothash;
pub mod txpool_fetcher;
44 changes: 44 additions & 0 deletions crates/rbuilder/benches/benchmarks/roothash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use criterion::{criterion_group, Criterion};
use eth_sparse_mpt::reth_sparse_trie::SparseTrieSharedCache;
use rbuilder::roothash::{calculate_state_root, RootHashConfig};
use reth_provider::{test_utils::create_test_provider_factory, ExecutionOutcome};
use revm_primitives::B256;

async fn calculate_state_root_util(use_sparse_trie: bool, compare_sparse_trie_output: bool) {
let provider = create_test_provider_factory();

let _ = calculate_state_root(
provider,
B256::default(),
&ExecutionOutcome::default(),
SparseTrieSharedCache::default(),
RootHashConfig::live_config(use_sparse_trie, compare_sparse_trie_output),
);
}

fn bench_calculate_state_root(c: &mut Criterion) {
let mut group = c.benchmark_group("Roothash calculator");
let rt = tokio::runtime::Runtime::new().unwrap();

group.bench_function(
"calculate_state_root_use_sparse_trie_compare_sparse_trie_output",
|b| {
b.to_async(&rt)
.iter(|| calculate_state_root_util(true, true));
},
);
group.bench_function("calculate_state_root_use_sparse_trie", |b| {
b.to_async(&rt)
.iter(|| calculate_state_root_util(true, false));
});
group.bench_function("calculate_state_root_compare_sparse_trie_output", |b| {
b.to_async(&rt)
.iter(|| calculate_state_root_util(false, true));
});
group.bench_function("calculate_state_root", |b| {
b.to_async(&rt)
.iter(|| calculate_state_root_util(false, false));
});
}

criterion_group!(roothash, bench_calculate_state_root);

0 comments on commit e584c4e

Please sign in to comment.