Skip to content

Commit

Permalink
use iter_custom
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Oct 26, 2024
1 parent c08859f commit 2fd16f0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/trie/sparse/benches/rlp_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(missing_docs, unreachable_pub)]

use std::time::{Duration, Instant};

use alloy_primitives::{B256, U256};
use criterion::{criterion_group, criterion_main, Criterion};
use prop::strategy::ValueTree;
Expand Down Expand Up @@ -51,10 +53,20 @@ pub fn update_rlp_node_level(c: &mut Criterion) {
group.bench_function(
format!("size {size} | updated {updated_leaves}% | depth {depth}"),
|b| {
b.iter_with_setup(
|| sparse.clone(),
|mut sparse| sparse.update_rlp_node_level(depth),
)
// Use `iter_custom` to avoid measuring clones and drops
b.iter_custom(|iters| {
let mut elapsed = Duration::ZERO;

let mut cloned = sparse.clone();
for _ in 0..iters {
let start = Instant::now();
cloned.update_rlp_node_level(depth);
elapsed += start.elapsed();
cloned = sparse.clone();
}

elapsed
})
},
);
}
Expand Down

0 comments on commit 2fd16f0

Please sign in to comment.