Skip to content

Commit

Permalink
add bench on mainnet blocks (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomoto911 authored Oct 23, 2024
1 parent b10fb83 commit 4f9d894
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ rust.unreachable_pub = "warn"
name = "gigagas"
harness = false

[[bench]]
name = "mainnet"
harness = false

[profile.release]
codegen-units = 1
panic = "abort"
Expand Down
80 changes: 80 additions & 0 deletions benches/mainnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![allow(missing_docs)]

#[path = "../tests/common/mod.rs"]
pub mod common;

use std::sync::Arc;

use alloy_chains::NamedChain;
use alloy_rpc_types::BlockTransactions;
use common::compat;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use grevm::GrevmScheduler;
use revm::primitives::{Env, TxEnv};

fn benchmark_mainnet(c: &mut Criterion) {
let db_latency_us = std::env::var("DB_LATENCY_US").map(|s| s.parse().unwrap()).unwrap_or(0);

common::for_each_block_from_disk(|block, mut db| {
db.latency_us = db_latency_us;
let mut group = c.benchmark_group(format!(
"Block {}({} txs, {} gas)",
block.header.number,
block.transactions.len(),
block.header.gas_used
));

let spec_id = compat::get_block_spec(&block.header);
let block_env = compat::get_block_env(&block.header);
let txs: Vec<TxEnv> = match block.transactions {
BlockTransactions::Full(txs) => {
txs.into_iter().map(|tx| compat::get_tx_env(tx)).collect()
}
_ => panic!("Missing transaction data"),
};

let mut env = Env::default();
env.cfg.chain_id = NamedChain::Mainnet.into();
env.block = block_env;

let db = Arc::new(db);

group.bench_function("Origin Sequential", |b| {
b.iter(|| {
common::execute_revm_sequential(
black_box(db.clone()),
black_box(spec_id),
black_box(env.clone()),
black_box(txs.clone()),
)
})
});

group.bench_function("Grevm Parallel", |b| {
b.iter(|| {
let executor = GrevmScheduler::new(
black_box(spec_id),
black_box(env.clone()),
black_box(db.clone()),
black_box(txs.clone()),
);
executor.parallel_execute()
})
});

group.bench_function("Grevm Sequential", |b| {
b.iter(|| {
let executor = GrevmScheduler::new(
black_box(spec_id),
black_box(env.clone()),
black_box(db.clone()),
black_box(txs.clone()),
);
executor.force_sequential_execute()
})
});
});
}

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

0 comments on commit 4f9d894

Please sign in to comment.