-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: migrate revme benchmarks to Criterion #1569
base: main
Are you sure you want to change the base?
Changes from 6 commits
765d33b
b9d8070
82d6344
2041aa0
a747898
46ff8cb
9793651
9c04849
d82c762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,12 +2,15 @@ use revm::{ | |||||
db::BenchmarkDB, | ||||||
inspector_handle_register, | ||||||
inspectors::TracerEip3155, | ||||||
primitives::{Address, Bytecode, TxKind}, | ||||||
interpreter::{ | ||||||
analysis::to_analysed, opcode::make_instruction_table, Contract, DummyHost, Interpreter, | ||||||
EMPTY_SHARED_MEMORY, | ||||||
}, | ||||||
primitives::{address, Address, Bytecode, Bytes, LatestSpec, TxKind}, | ||||||
Evm, | ||||||
}; | ||||||
use std::io::Error as IoError; | ||||||
use std::path::PathBuf; | ||||||
use std::time::Duration; | ||||||
use std::{borrow::Cow, fs}; | ||||||
use structopt::StructOpt; | ||||||
|
||||||
|
@@ -75,6 +78,12 @@ impl Cmd { | |||||
let input = hex::decode(self.input.trim()) | ||||||
.map_err(|_| Errors::InvalidInput)? | ||||||
.into(); | ||||||
|
||||||
if self.bench { | ||||||
run_benchmark(bytecode_str); | ||||||
return Ok(()); | ||||||
} | ||||||
|
||||||
// BenchmarkDB is dummy state that implements Database trait. | ||||||
// the bytecode is deployed at zero address. | ||||||
let mut evm = Evm::builder() | ||||||
|
@@ -91,17 +100,6 @@ impl Cmd { | |||||
}) | ||||||
.build(); | ||||||
|
||||||
if self.bench { | ||||||
// Microbenchmark | ||||||
let bench_options = microbench::Options::default().time(Duration::from_secs(3)); | ||||||
|
||||||
microbench::bench(&bench_options, "Run bytecode", || { | ||||||
let _ = evm.transact().unwrap(); | ||||||
}); | ||||||
|
||||||
return Ok(()); | ||||||
} | ||||||
|
||||||
let out = if self.trace { | ||||||
let mut evm = evm | ||||||
.modify() | ||||||
|
@@ -125,3 +123,36 @@ impl Cmd { | |||||
Ok(()) | ||||||
} | ||||||
} | ||||||
|
||||||
fn run_benchmark(bytecode_str: Cow<str>) { | ||||||
let evm = Evm::builder() | ||||||
.with_db(BenchmarkDB::new_bytecode(Bytecode::new())) | ||||||
.modify_tx_env(|tx| { | ||||||
tx.caller = address!("1000000000000000000000000000000000000000"); | ||||||
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); | ||||||
}) | ||||||
.build(); | ||||||
|
||||||
let host = DummyHost::new(*evm.context.evm.env.clone()); | ||||||
let instruction_table = make_instruction_table::<DummyHost, LatestSpec>(); | ||||||
let contract = Contract { | ||||||
input: Bytes::from(hex::decode("").unwrap()), | ||||||
bytecode: to_analysed(Bytecode::new_raw( | ||||||
hex::decode(bytecode_str.to_string()).unwrap().into(), | ||||||
)), | ||||||
..Default::default() | ||||||
}; | ||||||
let mut criterion = criterion::Criterion::default(); | ||||||
|
||||||
let mut criterion_group = criterion.benchmark_group("revme"); | ||||||
criterion_group.bench_function("bytecode", |b| { | ||||||
b.iter(|| { | ||||||
Interpreter::new(contract.clone(), u64::MAX, false).run( | ||||||
EMPTY_SHARED_MEMORY, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Shared memory is preallocated and shared between multiple calls, so having SharedMemory::new() will have an initialization hit but it will be slightly faster on memory expansion. |
||||||
&instruction_table, | ||||||
&mut host.clone(), | ||||||
); | ||||||
}) | ||||||
}); | ||||||
criterion_group.finish(); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont need builder here.