revme 14.0.0

Rust Ethereum Virtual Machine Executable
Documentation
use criterion::Criterion;
use revm::{
    bytecode::Bytecode,
    context::TxEnv,
    database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET},
    primitives::{bytes, hex, Bytes, TxKind},
    Context, ExecuteEvm, MainBuilder, MainContext,
};

const BYTES: &str = include_str!("analysis.hex");

pub fn run(criterion: &mut Criterion) {
    let bytecode = Bytecode::new_raw(Bytes::from(hex::decode(BYTES).unwrap()));
    // BenchmarkDB is dummy state that implements Database trait.
    let context = Context::mainnet()
        .with_db(BenchmarkDB::new_bytecode(bytecode))
        .modify_cfg_chained(|c| c.disable_nonce_check = true);
    let tx = TxEnv::builder()
        .caller(BENCH_CALLER)
        .kind(TxKind::Call(BENCH_TARGET))
        .data(bytes!("8035F0CE"))
        .build()
        .unwrap();
    let mut evm = context.build_mainnet();
    criterion.bench_function("analysis", |b| {
        b.iter_batched(
            || tx.clone(),
            |input| evm.transact_one(input).unwrap(),
            criterion::BatchSize::SmallInput,
        );
    });
}