Skip to content

Commit

Permalink
Merge pull request #2870 from OffchainLabs/stylus_bench_improvements
Browse files Browse the repository at this point in the history
More benchmarks in stylus_benchmark
  • Loading branch information
eljobe authored Jan 20, 2025
2 parents 9fe417e + 0d05845 commit b84847a
Show file tree
Hide file tree
Showing 26 changed files with 942 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/arbitrator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ jobs:
- name: Run rust tests
run: cargo test -p arbutil -p prover -p jit -p stylus --release --manifest-path arbitrator/prover/Cargo.toml

- name: Check stylus_bechmark
run: cargo check --manifest-path arbitrator/tools/stylus_benchmark/Cargo.toml

- name: Rustfmt
run: cargo fmt -p arbutil -p prover -p jit -p stylus --manifest-path arbitrator/Cargo.toml -- --check

Expand Down
4 changes: 2 additions & 2 deletions arbitrator/jit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ pub fn new_program(
)));
};

exec_program(exec, module, calldata, config, evm_data, gas)
launch_program_thread(exec, module, calldata, config, evm_data, gas)
}

pub fn exec_program(
pub fn launch_program_thread(
exec: &mut WasmEnv,
module: Arc<[u8]>,
calldata: Vec<u8>,
Expand Down
13 changes: 7 additions & 6 deletions arbitrator/tools/stylus_benchmark/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions arbitrator/tools/stylus_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ stylus = { path = "../../stylus/", default-features = false }
clap = { version = "4.4.8", features = ["derive"] }
strum = "0.26"
strum_macros = "0.26"
rand = "0.8.5"
10 changes: 5 additions & 5 deletions arbitrator/tools/stylus_benchmark/src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024, Offchain Labs, Inc.
// Copyright 2021-2025, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

use arbutil::evm::{api::Ink, EvmData};
Expand Down Expand Up @@ -45,7 +45,7 @@ fn run(compiled_module: Vec<u8>) -> (Duration, Ink) {

let exec = &mut WasmEnv::default();

let module = jit::program::exec_program(
let module = jit::program::launch_program_thread(
exec,
compiled_module.into(),
calldata,
Expand Down Expand Up @@ -94,11 +94,11 @@ pub fn benchmark(wat: Vec<u8>) -> eyre::Result<()> {
durations = durations[l..r].to_vec();

let avg_duration = durations.iter().sum::<Duration>() / (r - l) as u32;
let avg_ink_spent_per_micro_second = ink_spent.0 / avg_duration.as_micros() as u64;
let avg_ink_spent_per_nano_second = ink_spent.0 / avg_duration.as_nanos() as u64;
println!("After discarding top and bottom runs: ");
println!(
"avg_duration: {:?}, avg_ink_spent_per_micro_second: {:?}",
avg_duration, avg_ink_spent_per_micro_second
"avg_duration: {:?}, avg_ink_spent_per_nano_second: {:?}",
avg_duration, avg_ink_spent_per_nano_second
);

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions arbitrator/tools/stylus_benchmark/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2021-2024, Offchain Labs, Inc.
// Copyright 2021-2025, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

mod benchmark;
mod scenario;
mod scenarios;

use clap::Parser;
use clap::{Parser, ValueEnum};
use scenario::Scenario;
use std::path::PathBuf;
use strum::IntoEnumIterator;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand All @@ -20,7 +20,7 @@ struct Args {
}

fn handle_scenario(scenario: Scenario, output_wat_dir_path: Option<PathBuf>) -> eyre::Result<()> {
println!("Benchmarking {}", scenario);
println!("Benchmarking {:?}", scenario);
let wat = scenario::generate_wat(scenario, output_wat_dir_path);
benchmark::benchmark(wat)
}
Expand All @@ -32,8 +32,8 @@ fn main() -> eyre::Result<()> {
Some(scenario) => handle_scenario(scenario, args.output_wat_dir_path),
None => {
println!("No scenario specified, benchmarking all scenarios\n");
for scenario in Scenario::iter() {
let benchmark_result = handle_scenario(scenario, args.output_wat_dir_path.clone());
for scenario in Scenario::value_variants() {
let benchmark_result = handle_scenario(*scenario, args.output_wat_dir_path.clone());
if let Err(err) = benchmark_result {
return Err(err);
}
Expand Down
Loading

0 comments on commit b84847a

Please sign in to comment.