Skip to content

Commit

Permalink
Benchmark XorI32
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoximenes committed Dec 20, 2024
1 parent 1fcab9f commit 367f77b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions arbitrator/tools/stylus_benchmark/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use strum_macros::{Display, EnumIter, EnumString};
pub enum Scenario {
#[strum(serialize = "add_i32")]
AddI32,
#[strum(serialize = "xor_i32")]
XorI32,
}

fn write_wat_beginning(wat: &mut Vec<u8>) {
Expand Down Expand Up @@ -92,9 +94,35 @@ fn generate_add_i32_wat() -> Vec<u8> {
wat.to_vec()
}

fn generate_xor_i32_wat() -> Vec<u8> {
let number_of_loop_iterations = 10_000;
let number_of_ops_per_loop_iteration = 2000;

let mut wat = Vec::new();

write_wat_beginning(&mut wat);

// ops to be benchmarked
wat.write_all(b" i32.const 1231\n").unwrap();
for _ in 0..number_of_ops_per_loop_iteration {
wat.write_all(b" i32.const 12312313\n").unwrap();
wat.write_all(b" i32.xor\n").unwrap();
}
wat.write_all(b" drop\n").unwrap();

write_wat_end(
&mut wat,
number_of_loop_iterations,
number_of_ops_per_loop_iteration,
);

wat.to_vec()
}

pub fn generate_wat(scenario: Scenario, output_wat_dir_path: Option<PathBuf>) -> Vec<u8> {
let wat = match scenario {
Scenario::AddI32 => generate_add_i32_wat(),
Scenario::XorI32 => generate_xor_i32_wat(),
};

// print wat to file if needed
Expand Down

0 comments on commit 367f77b

Please sign in to comment.