revme/cmd/bench/
snailtracer.rs

1use criterion::Criterion;
2use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
3use revm::{
4    bytecode::Bytecode,
5    primitives::{bytes, hex, Bytes, TxKind},
6    Context, ExecuteEvm, MainBuilder, MainContext,
7};
8
9pub fn run(criterion: &mut Criterion) {
10    let bytecode = Bytecode::new_raw(Bytes::from(hex::decode(BYTES).unwrap()));
11
12    let mut evm = Context::mainnet()
13        .with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
14        .modify_tx_chained(|tx| {
15            // Execution globals block hash/gas_limit/coinbase/timestamp..
16            tx.caller = BENCH_CALLER;
17            tx.kind = TxKind::Call(BENCH_TARGET);
18            tx.data = bytes!("30627b7c");
19            tx.gas_limit = 1_000_000_000;
20        })
21        .build_mainnet();
22    criterion.bench_function("snailtracer", |b| {
23        b.iter(|| {
24            let _ = evm.replay().unwrap();
25        })
26    });
27}
28
29const BYTES: &str = include_str!("snailtracer.hex");