revme/cmd/bench/
analysis.rs

1use context::TxEnv;
2use criterion::Criterion;
3use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
4use revm::{
5    bytecode::Bytecode,
6    primitives::{bytes, hex, Bytes, TxKind},
7    Context, ExecuteEvm, MainBuilder, MainContext,
8};
9
10const BYTES: &str = include_str!("analysis.hex");
11
12pub fn run(criterion: &mut Criterion) {
13    let bytecode = Bytecode::new_raw(Bytes::from(hex::decode(BYTES).unwrap()));
14    // BenchmarkDB is dummy state that implements Database trait.
15    let context = Context::mainnet()
16        .with_db(BenchmarkDB::new_bytecode(bytecode))
17        .modify_cfg_chained(|c| c.disable_nonce_check = true);
18    let tx = TxEnv::builder()
19        .caller(BENCH_CALLER)
20        .kind(TxKind::Call(BENCH_TARGET))
21        .data(bytes!("8035F0CE"))
22        .build()
23        .unwrap();
24    let mut evm = context.build_mainnet();
25    criterion.bench_function("analysis", |b| {
26        b.iter_batched(
27            || {
28                // create a transaction input
29                tx.clone()
30            },
31            |input| {
32                let _ = evm.transact_one(input);
33            },
34            criterion::BatchSize::SmallInput,
35        );
36    });
37}