feat: set up codspeed (#13372)

This commit is contained in:
DaniPopes
2024-12-20 13:21:51 +02:00
committed by GitHub
parent 3966130844
commit a4f86b0e2d
34 changed files with 318 additions and 398 deletions

View File

@ -1,4 +1,4 @@
#![allow(missing_docs, unreachable_pub)]
#![allow(missing_docs)]
use alloy_primitives::{map::B256HashMap, B256, U256};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
@ -15,11 +15,17 @@ use reth_trie::{
use reth_trie_common::{HashBuilder, Nibbles};
use reth_trie_sparse::SparseTrie;
pub fn calculate_root_from_leaves(c: &mut Criterion) {
fn calculate_root_from_leaves(c: &mut Criterion) {
let mut group = c.benchmark_group("calculate root from leaves");
group.sample_size(20);
for size in [1_000, 5_000, 10_000, 100_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && size > 5_000 {
continue;
}
let state = generate_test_data(size);
// hash builder
@ -29,6 +35,7 @@ pub fn calculate_root_from_leaves(c: &mut Criterion) {
hb.add_leaf(Nibbles::unpack(key), &alloy_rlp::encode_fixed_size(value));
}
hb.root();
hb
})
});
@ -44,19 +51,32 @@ pub fn calculate_root_from_leaves(c: &mut Criterion) {
.unwrap();
}
sparse.root().unwrap();
sparse
})
});
}
}
pub fn calculate_root_from_leaves_repeated(c: &mut Criterion) {
fn calculate_root_from_leaves_repeated(c: &mut Criterion) {
let mut group = c.benchmark_group("calculate root from leaves repeated");
group.sample_size(20);
for init_size in [1_000, 10_000, 100_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && init_size > 10_000 {
continue;
}
let init_state = generate_test_data(init_size);
for update_size in [100, 1_000, 5_000, 10_000] {
// Too slow.
#[allow(unexpected_cfgs)]
if cfg!(codspeed) && update_size > 1_000 {
continue;
}
for num_updates in [1, 3, 5, 10] {
let updates =
(0..num_updates).map(|_| generate_test_data(update_size)).collect::<Vec<_>>();