Skip to content

Commit ddb8550

Browse files
committed
chore(benches): clean up criterion callsites
1 parent 3ad3116 commit ddb8550

File tree

10 files changed

+53
-96
lines changed

10 files changed

+53
-96
lines changed

bins/revme/src/cmd/bench/analysis.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ pub fn run(criterion: &mut Criterion) {
2424
let mut evm = context.build_mainnet();
2525
criterion.bench_function("analysis", |b| {
2626
b.iter_batched(
27-
|| {
28-
// create a transaction input
29-
tx.clone()
30-
},
31-
|input| {
32-
let _ = evm.transact_one(input);
33-
},
27+
|| tx.clone(),
28+
|input| evm.transact_one(input).unwrap(),
3429
criterion::BatchSize::SmallInput,
3530
);
3631
});

bins/revme/src/cmd/bench/burntpix.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,8 @@ pub fn run(criterion: &mut Criterion) {
5151

5252
criterion.bench_function("burntpix", |b| {
5353
b.iter_batched(
54-
|| {
55-
// create a transaction input
56-
tx.clone()
57-
},
58-
|input| {
59-
evm.transact_one(input).unwrap();
60-
},
54+
|| tx.clone(),
55+
|input| evm.transact_one(input).unwrap(),
6156
criterion::BatchSize::SmallInput,
6257
);
6358
});

bins/revme/src/cmd/bench/gas_cost_estimator.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ pub fn run(criterion: &mut Criterion) {
3535

3636
criterion.bench_function(name, |b| {
3737
b.iter_batched(
38-
|| {
39-
// create a transaction input
40-
tx.clone()
41-
},
42-
|input| {
43-
let _ = evm.transact_one(input).unwrap();
44-
},
38+
|| tx.clone(),
39+
|input| evm.transact_one(input).unwrap(),
4540
criterion::BatchSize::SmallInput,
4641
);
4742
});

bins/revme/src/cmd/bench/snailtracer.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,16 @@ pub fn run(criterion: &mut Criterion) {
2727

2828
criterion.bench_function("snailtracer", |b| {
2929
b.iter_batched(
30-
|| {
31-
// create a transaction input
32-
tx.clone()
33-
},
34-
|input| {
35-
let _ = evm.transact_one(input).unwrap();
36-
},
30+
|| tx.clone(),
31+
|input| evm.transact_one(input).unwrap(),
3732
criterion::BatchSize::SmallInput,
3833
);
3934
});
4035

4136
criterion.bench_function("analysis-inspector", |b| {
4237
b.iter_batched(
43-
|| {
44-
// create a transaction input
45-
tx.clone()
46-
},
47-
|input| {
48-
let _ = evm.inspect_one_tx(input);
49-
},
38+
|| tx.clone(),
39+
|input| evm.inspect_one_tx(input),
5040
criterion::BatchSize::SmallInput,
5141
);
5242
});

bins/revme/src/cmd/bench/transfer.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ pub fn run(criterion: &mut Criterion) {
2828
let mut i = 0;
2929
criterion.bench_function("transfer", |b| {
3030
b.iter_batched(
31-
|| {
32-
// create a transfer input
33-
tx.clone()
34-
},
31+
|| tx.clone(),
3532
|input| {
3633
i += 1;
37-
evm.transact_one(input).unwrap();
34+
evm.transact_one(input).unwrap()
3835
},
3936
criterion::BatchSize::SmallInput,
4037
);
@@ -57,9 +54,5 @@ pub fn run(criterion: &mut Criterion) {
5754

5855
evm.modify_cfg(|cfg| cfg.disable_nonce_check = false);
5956

60-
criterion.bench_function("transfer_finalize", |b| {
61-
b.iter(|| {
62-
let _ = evm.replay().unwrap();
63-
})
64-
});
57+
criterion.bench_function("transfer_finalize", |b| b.iter(|| evm.replay().unwrap()));
6558
}

bins/revme/src/cmd/bench/transfer_multi.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ pub fn run(criterion: &mut Criterion) {
5151

5252
criterion.bench_function("transact_commit_1000txs", |b| {
5353
b.iter_batched(
54-
|| {
55-
// create transaction inputs
56-
txs.clone()
57-
},
54+
|| txs.clone(),
5855
|inputs| {
5956
for tx in inputs {
6057
let _ = evm.transact_commit(tx).unwrap();
@@ -66,10 +63,7 @@ pub fn run(criterion: &mut Criterion) {
6663

6764
criterion.bench_function("transact_1000tx_commit_inner_every_40", |b| {
6865
b.iter_batched(
69-
|| {
70-
// create transaction inputs
71-
txs.clone()
72-
},
66+
|| txs.clone(),
7367
|inputs| {
7468
for (i, tx) in inputs.into_iter().enumerate() {
7569
let _ = evm.transact_one(tx).unwrap();

bins/revme/src/cmd/evmrunner.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,29 @@ impl Cmd {
109109
.without_plots();
110110
let mut criterion_group = criterion.benchmark_group("revme");
111111
criterion_group.bench_function("evm", |b| {
112-
b.iter(|| {
113-
let _ = evm.transact(tx.clone()).unwrap();
114-
})
112+
b.iter_batched(
113+
|| tx.clone(),
114+
|input| evm.transact(input).unwrap(),
115+
criterion::BatchSize::SmallInput,
116+
);
115117
});
116118
criterion_group.finish();
117119

118120
return Ok(());
119121
}
120122

121123
let time = Instant::now();
122-
let state = if self.trace {
123-
evm.inspect_tx(tx.clone())
124-
.map_err(|_| Errors::EVMError)?
125-
.state
124+
let r = if self.trace {
125+
evm.inspect_tx(tx)
126126
} else {
127-
let out = evm.transact(tx.clone()).map_err(|_| Errors::EVMError)?;
128-
println!("Result: {:#?}", out.result);
129-
out.state
130-
};
127+
evm.transact(tx)
128+
}
129+
.map_err(|_| Errors::EVMError)?;
131130
let time = time.elapsed();
132131

132+
println!("Result: {:#?}", r.result);
133133
if self.state {
134-
println!("State: {state:#?}");
134+
println!("State: {:#?}", r.state);
135135
}
136136

137137
println!("Elapsed: {time:?}");

bins/revme/src/main.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
use clap::Parser;
2-
use revme::cmd::{Error, MainCmd};
2+
use revme::cmd::MainCmd;
3+
use std::process::ExitCode;
34

4-
fn main() -> Result<(), Error> {
5-
set_thread_panic_hook();
6-
MainCmd::parse().run().inspect_err(|e| println!("{e:?}"))
7-
}
5+
fn main() -> ExitCode {
6+
if std::env::var_os("RUST_BACKTRACE").is_none() {
7+
unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
8+
}
89

9-
/// Sets thread panic hook, useful for having tests that panic.
10-
fn set_thread_panic_hook() {
11-
use std::{
12-
backtrace::Backtrace,
13-
panic::{set_hook, take_hook},
14-
process::exit,
15-
};
16-
let orig_hook = take_hook();
17-
set_hook(Box::new(move |panic_info| {
18-
println!("Custom backtrace: {}", Backtrace::capture());
19-
orig_hook(panic_info);
20-
exit(1);
21-
}));
10+
match MainCmd::parse().run() {
11+
Ok(()) => ExitCode::SUCCESS,
12+
Err(e) => {
13+
eprintln!("error:\n- {e}\n- {e:#?}");
14+
ExitCode::FAILURE
15+
}
16+
}
2217
}

crates/bytecode/src/iter.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::{opcode, Bytecode, OpCode};
66
/// without dealing with the immediate values that follow instructions.
77
#[derive(Debug, Clone)]
88
pub struct BytecodeIterator<'a> {
9-
/// Start pointer of the bytecode. Only used to calculate [`position`](Self::position).
10-
start: *const u8,
119
/// Iterator over the bytecode bytes.
1210
bytes: core::slice::Iter<'a, u8>,
11+
/// Start pointer of the bytecode. Only used to calculate [`position`](Self::position).
12+
start: *const u8,
1313
}
1414

1515
impl<'a> BytecodeIterator<'a> {
@@ -21,8 +21,8 @@ impl<'a> BytecodeIterator<'a> {
2121
Bytecode::Eip7702(_) => &[],
2222
};
2323
Self {
24-
start: bytes.as_ptr(),
2524
bytes: bytes.iter(),
25+
start: bytes.as_ptr(),
2626
}
2727
}
2828

@@ -40,15 +40,13 @@ impl<'a> BytecodeIterator<'a> {
4040
/// Returns the current position in the bytecode.
4141
#[inline]
4242
pub fn position(&self) -> usize {
43-
(self.bytes.as_slice().as_ptr() as usize) - (self.start as usize)
44-
// TODO: Use the following on 1.87
4543
// SAFETY: `start` always points to the start of the bytecode.
46-
// unsafe {
47-
// self.bytes
48-
// .as_slice()
49-
// .as_ptr()
50-
// .offset_from_unsigned(self.start)
51-
// }
44+
unsafe {
45+
self.bytes
46+
.as_slice()
47+
.as_ptr()
48+
.offset_from_unsigned(self.start)
49+
}
5250
}
5351

5452
#[inline]

crates/handler/src/instructions.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ where
4545
Self::new(instruction_table::<WIRE, HOST>())
4646
}
4747

48-
/// Rerurns new `EthInstructions` with custom instruction table.
48+
/// Returns an instance new `EthInstructions` with custom instruction table.
49+
#[inline]
4950
pub fn new(base_table: InstructionTable<WIRE, HOST>) -> Self {
5051
Self {
5152
instruction_table: Box::new(base_table),
5253
}
5354
}
5455

55-
/// Inserts a new instruction into the instruction table.s
56+
/// Inserts a new instruction into the instruction table.
57+
#[inline]
5658
pub fn insert_instruction(&mut self, opcode: u8, instruction: Instruction<WIRE, HOST>) {
5759
self.instruction_table[opcode as usize] = instruction;
5860
}

0 commit comments

Comments
 (0)