From 72fe9903a16dc8d6bfcd20376cbd060fbf268c40 Mon Sep 17 00:00:00 2001 From: Bennett Petzold Date: Thu, 23 Jan 2025 14:42:44 -0500 Subject: [PATCH] Add simple benchmarks with static obj files --- Cargo.toml | 5 ++ benches/executor_compare.rs | 90 ++++++++++++++++++++++++++++++++++++ penn_sim/lc3os.obj | Bin 0 -> 1272 bytes test_data/custom/loop.asm | 5 ++ test_data/custom/loop.obj | Bin 0 -> 10 bytes 5 files changed, 100 insertions(+) create mode 100644 benches/executor_compare.rs create mode 100644 penn_sim/lc3os.obj create mode 100644 test_data/custom/loop.asm create mode 100644 test_data/custom/loop.obj diff --git a/Cargo.toml b/Cargo.toml index f6acdb3..86f4e26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,10 @@ path = "src/cli.rs" name = "testcli" path = "src/testcli.rs" +[[bench]] +name = "executor_compare" +harness = false + [features] default = [] consolidated = ["dep:pinned-init"] @@ -36,6 +40,7 @@ bare_err_tree = "0.7" pinned-init = { version = "0.0.9", optional = true, default-features = false, features = ["std"] } [dev-dependencies] +criterion = { version = "0.5", features = ["html_reports"] } # To reduce getter boilerplate derive-getters = "0.5" # More efficient map initialization diff --git a/benches/executor_compare.rs b/benches/executor_compare.rs new file mode 100644 index 0000000..f959bd2 --- /dev/null +++ b/benches/executor_compare.rs @@ -0,0 +1,90 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use lc3sim_project::{ + executors::{core::CoreLC3, populate_from_bin, LC3}, + harnesses::{simple::FailIO, sync::step_continue}, +}; + +macro_rules! setup_lc3 { + ( $lc3:ident, $path:literal ) => { + || { + let mut lc3 = $lc3.clone(); + populate_from_bin(&mut lc3, include_bytes!("../penn_sim/lc3os.obj").as_slice()); + populate_from_bin(&mut lc3, include_bytes!($path).as_slice()); + lc3 + } + }; +} + +pub fn create_new(c: &mut Criterion) { + let mut c = c.benchmark_group("create_new"); + + macro_rules! bench_new { + ( $lc3:expr, $name: literal ) => { + c.bench_function($name, |b| { + b.iter($lc3); + }); + }; + } + + bench_new!(CoreLC3::new, "core"); + #[cfg(feature = "consolidated")] + bench_new!( + lc3sim_project::executors::consolidated::ConsolidatedLC3::boxed, + "consolidated" + ); +} + +pub fn load_os(c: &mut Criterion) { + let mut c = c.benchmark_group("load_os"); + + fn exec_setup(mut lc3: E) -> E { + populate_from_bin(&mut lc3, include_bytes!("../penn_sim/lc3os.obj").as_slice()); + black_box(lc3) + } + + macro_rules! bench_load { + ( $lc3:expr, $name: literal ) => { + c.bench_function($name, |b| { + b.iter_batched($lc3, exec_setup, criterion::BatchSize::SmallInput); + }); + }; + } + + bench_load!(CoreLC3::new, "core"); + #[cfg(feature = "consolidated")] + bench_load!( + lc3sim_project::executors::consolidated::ConsolidatedLC3::boxed, + "consolidated" + ); +} + +pub fn tiny_loop(c: &mut Criterion) { + let mut c = c.benchmark_group("tiny_loop"); + + fn exec_loop(mut lc3: E) { + step_continue(&mut FailIO, &mut lc3).unwrap(); + } + + macro_rules! bench_loop { + ( $lc3:expr, $name: literal ) => { + let lc3 = $lc3; + c.bench_function($name, |b| { + b.iter_batched( + setup_lc3!(lc3, "../test_data/custom/loop.obj"), + exec_loop, + criterion::BatchSize::SmallInput, + ); + }); + }; + } + + bench_loop!(CoreLC3::new(), "core"); + #[cfg(feature = "consolidated")] + bench_loop!( + lc3sim_project::executors::consolidated::ConsolidatedLC3::boxed(), + "consolidated" + ); +} + +criterion_group!(speed_compare, create_new, load_os, tiny_loop); +criterion_main!(speed_compare); diff --git a/penn_sim/lc3os.obj b/penn_sim/lc3os.obj new file mode 100644 index 0000000000000000000000000000000000000000..23f8cefc2981f46153bf11e86ae1d06aef927f39 GIT binary patch literal 1272 zcmZQzU`nA7$}%Z3sWX`{IWWajXcDC^8P!it2&6KN!Vw$-3Q`-m6vQ{M>xmyc_>bWq z(?6DfZ2vg^as3ne|BnF+sQ=IKpFxBFhXKRF7wrEQK0kQC_{-v_?Ef}CQT}l7fZ;Ra zXZEj!6cQX*m_H~ACG!7PysLay|Ixt%_KzMId{FwJ@Ile=N`QiZ)(1t!3;H*JI?fuO zH9c#7*8YN!LW+ap#Q-K2{tt=)3St@p3?d8I7zGqXn#BGy{}fPwn)p_6i}DuLE$UnJ zw;w#PaINz80LG20_~-EdYG7dCV(?_hV<=!KWhh}#U`PbwWQGhNT?E9*K(SOH%MK{Y F002qMBIE!7 literal 0 HcmV?d00001 diff --git a/test_data/custom/loop.asm b/test_data/custom/loop.asm new file mode 100644 index 0000000..7c63653 --- /dev/null +++ b/test_data/custom/loop.asm @@ -0,0 +1,5 @@ + .ORIG x3000 + AND R0, R0, #0 +LOOP ADD R0, R0, #1 + BRnp LOOP + HALT diff --git a/test_data/custom/loop.obj b/test_data/custom/loop.obj new file mode 100644 index 0000000000000000000000000000000000000000..3ccb4bc9a339fec93e8deb4a1805535a874e8d03 GIT binary patch literal 10 RcmXqD2v87E