revme/cmd/
bench.rs

1pub mod analysis;
2pub mod burntpix;
3pub mod evm_build;
4pub mod gas_cost_estimator;
5pub mod snailtracer;
6pub mod transfer;
7pub mod transfer_multi;
8
9use clap::{Parser, ValueEnum};
10
11#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
12pub enum BenchName {
13    Analysis,
14    Burntpix,
15    Snailtracer,
16    Transfer,
17    EvmBuild,
18    TransferMulti,
19    GasCostEstimator,
20}
21
22impl BenchName {
23    pub const ALL: &[BenchName] = &[
24        BenchName::Analysis,
25        BenchName::Burntpix,
26        BenchName::Snailtracer,
27        BenchName::Transfer,
28        BenchName::TransferMulti,
29        BenchName::EvmBuild,
30        BenchName::GasCostEstimator,
31    ];
32
33    pub fn as_str(self) -> &'static str {
34        match self {
35            BenchName::Analysis => "analysis",
36            BenchName::Burntpix => "burntpix",
37            BenchName::Snailtracer => "snailtracer",
38            BenchName::Transfer => "transfer",
39            BenchName::EvmBuild => "evm-build",
40            BenchName::TransferMulti => "transfer-multi",
41            BenchName::GasCostEstimator => "gas-cost-estimator",
42        }
43    }
44}
45
46/// `bytecode` subcommand
47#[derive(Parser, Debug)]
48pub struct Cmd {
49    #[arg(value_enum)]
50    pub name: BenchName,
51    /// Warmup represents warm up time for benchmarks ran
52    #[arg(short = 'w', long)]
53    pub warmup: Option<f64>,
54    /// Samples represents default measurement time for benchmarks ran
55    #[arg(short = 'm', long)]
56    pub time: Option<f64>,
57    /// Samples represents size of the sample for benchmarks ran
58    #[arg(short = 's', long)]
59    pub samples: Option<usize>,
60}
61
62impl Cmd {
63    /// Runs bench command.
64    pub fn run(&self) {
65        let mut criterion = criterion::Criterion::default()
66            .warm_up_time(std::time::Duration::from_secs_f64(
67                self.warmup.unwrap_or(0.5),
68            ))
69            // Measurement_time of 0.1 will get 500+ iterations for analysis and transfer and will be extended if needed in order to test the given sample size (minimum sample size is 10 per criterion documentation) as is the case with burntpix and snailtracer benchmark tests
70            .measurement_time(std::time::Duration::from_secs_f64(self.time.unwrap_or(1.5)))
71            .sample_size(self.samples.unwrap_or(10));
72
73        match self.name {
74            BenchName::Analysis => {
75                analysis::run(&mut criterion);
76            }
77            BenchName::Burntpix => {
78                burntpix::run(&mut criterion);
79            }
80            BenchName::Snailtracer => {
81                snailtracer::run(&mut criterion);
82            }
83            BenchName::Transfer => {
84                transfer::run(&mut criterion);
85            }
86            BenchName::EvmBuild => {
87                evm_build::run(&mut criterion);
88            }
89            BenchName::TransferMulti => {
90                transfer_multi::run(&mut criterion);
91            }
92            BenchName::GasCostEstimator => {
93                gas_cost_estimator::run(&mut criterion);
94            }
95        }
96    }
97}