revme/cmd/bench/
transfer_multi.rs

1use context::TxEnv;
2use criterion::Criterion;
3use database::{InMemoryDB, BENCH_CALLER, BENCH_TARGET};
4use revm::{
5    interpreter::instructions::utility::IntoAddress,
6    primitives::{TxKind, U256},
7    Context, ExecuteCommitEvm, ExecuteEvm, MainBuilder, MainContext,
8};
9use state::AccountInfo;
10
11pub fn run(criterion: &mut Criterion) {
12    let mut db = InMemoryDB::default();
13
14    let address = U256::from(10000);
15    for i in 0..10000 {
16        db.insert_account_info(
17            (address + U256::from(i)).into_address(),
18            AccountInfo::from_balance(U256::from(3_000_000_000u32)),
19        );
20    }
21    db.insert_account_info(
22        BENCH_TARGET,
23        AccountInfo::from_balance(U256::from(3_000_000_000u32)),
24    );
25
26    db.insert_account_info(
27        BENCH_CALLER,
28        AccountInfo::from_balance(U256::from(3_000_000_000u32)),
29    );
30
31    let mut evm = Context::mainnet()
32        .with_db(db)
33        .modify_cfg_chained(|cfg| cfg.disable_nonce_check = true)
34        .build_mainnet();
35
36    let target = U256::from(10000);
37    let mut txs = Vec::with_capacity(1000);
38
39    for i in 0..1000 {
40        let tx = TxEnv::builder()
41            .caller(BENCH_CALLER)
42            .kind(TxKind::Call((target + U256::from(i)).into_address()))
43            .value(U256::from(1))
44            .gas_price(0)
45            .gas_priority_fee(None)
46            .gas_limit(30_000)
47            .build()
48            .unwrap();
49        txs.push(tx);
50    }
51
52    criterion.bench_function("transact_commit_1000txs", |b| {
53        b.iter_batched(
54            || {
55                // create transaction inputs
56                txs.clone()
57            },
58            |inputs| {
59                for tx in inputs {
60                    let _ = evm.transact_commit(tx).unwrap();
61                }
62            },
63            criterion::BatchSize::SmallInput,
64        );
65    });
66
67    criterion.bench_function("transact_1000tx_commit_inner_every_40", |b| {
68        b.iter_batched(
69            || {
70                // create transaction inputs
71                txs.clone()
72            },
73            |inputs| {
74                for (i, tx) in inputs.into_iter().enumerate() {
75                    let _ = evm.transact_one(tx).unwrap();
76                    if i % 40 == 0 {
77                        evm.commit_inner();
78                    }
79                }
80                evm.commit_inner();
81            },
82            criterion::BatchSize::SmallInput,
83        );
84    });
85}