From 26a78930948df31c9628d16b7c8193de516cfcc6 Mon Sep 17 00:00:00 2001 From: Diego Ximenes Date: Fri, 13 Dec 2024 09:23:20 -0300 Subject: [PATCH] Prints avg_ink_spent_per_micro_second --- .../tools/stylus_benchmark/src/benchmark.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arbitrator/tools/stylus_benchmark/src/benchmark.rs b/arbitrator/tools/stylus_benchmark/src/benchmark.rs index 1c3ab363c6..b5b3c78038 100644 --- a/arbitrator/tools/stylus_benchmark/src/benchmark.rs +++ b/arbitrator/tools/stylus_benchmark/src/benchmark.rs @@ -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 = 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 @@ -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::(); - println!( - "Average duration after discarding top and bottom runs: {:?}", - sum / (r - l) as u32 - ); + let avg_duration = durations.iter().sum::() / (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(()) }