revme/cmd/bench/
transfer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use database::{BenchmarkDB, EthereumBenchmarkWiring};
use revm::{
    bytecode::Bytecode,
    primitives::{TxKind, U256},
    Evm,
};
use std::time::Duration;

pub fn run() {
    // BenchmarkDB is dummy state that implements Database trait.
    let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
        .with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
        .with_default_ext_ctx()
        .modify_tx_env(|tx| {
            // execution globals block hash/gas_limit/coinbase/timestamp..
            tx.caller = "0x0000000000000000000000000000000000000001"
                .parse()
                .unwrap();
            tx.value = U256::from(10);
            tx.transact_to = TxKind::Call(
                "0x0000000000000000000000000000000000000000"
                    .parse()
                    .unwrap(),
            );
        })
        .build();

    // Microbenchmark
    let bench_options = microbench::Options::default().time(Duration::from_secs(3));

    microbench::bench(&bench_options, "Simple value transfer", || {
        let _ = evm.transact().unwrap();
    });
}