Skip to content

Commit

Permalink
Prints avg_ink_spent_per_micro_second
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoximenes committed Dec 13, 2024
1 parent 0fb2960 commit 26a7893
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions arbitrator/tools/stylus_benchmark/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ pub fn benchmark(wat_path: PathBuf) -> eyre::Result<()> {
let compiled_module = compile(&wasm, 2, true, Target::default())?;

let mut durations: Vec<Duration> = Vec::new();
let mut ink_spent = Ink(0);
for i in 0..NUMBER_OF_BENCHMARK_RUNS {
print!("Run {:?}, ", i);
let (duration, ink) = run(compiled_module.clone());
durations.push(duration);
println!("duration: {:?}, ink: {:?}", duration, ink);
let (duration_run, ink_spent_run) = run(compiled_module.clone());
durations.push(duration_run);
ink_spent = ink_spent_run;
println!("duration: {:?}, ink_spent: {:?}", duration_run, ink_spent_run);
}

// discard top and bottom runs
Expand All @@ -102,11 +104,10 @@ pub fn benchmark(wat_path: PathBuf) -> eyre::Result<()> {
let r = NUMBER_OF_BENCHMARK_RUNS as usize - NUMBER_OF_TOP_AND_BOTTOM_RUNS_TO_DISCARD as usize;
durations = durations[l..r].to_vec();

let sum = durations.iter().sum::<Duration>();
println!(
"Average duration after discarding top and bottom runs: {:?}",
sum / (r - l) as u32
);
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;
println!("After discarding top and bottom runs: ");
println!("avg_duration: {:?}, avg_ink_spent_per_micro_second: {:?}", avg_duration, avg_ink_spent_per_micro_second);

Ok(())
}

0 comments on commit 26a7893

Please sign in to comment.