Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Alternative LC3 Executor and I/O Implementations #10

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ path = "src/cli.rs"
name = "testcli"
path = "src/testcli.rs"

[[bench]]
name = "executor_compare"
harness = false

[features]
default = []
consolidated = ["dep:pinned-init"]
cached_resolve = ["dep:pinned-init"]
instruction_mem = ["dep:pinned-init"]

[dependencies]
anyhow = "1.0.95"
once_cell = "1.20.2"
Expand All @@ -26,13 +36,19 @@ strum = { version = "0.26.3", features = ["derive"] }
strum_macros = "0.26.4"
# To reduce error boilerplate
thiserror = "2"
# For better error tracking
bare_err_tree = "0.7"
# Creating large struct parts directly on the heap
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
once_map = "0.4"
# Reducing test writing boilerplate via macro
paste = "1"
stable_deref_trait = "1"
# Random tempfile names
uuid = { version = "1", features = ["v4"] }
123 changes: 123 additions & 0 deletions benches/executor_compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use std::time::Duration;

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"
);
#[cfg(feature = "cached_resolve")]
bench_new!(
lc3sim_project::executors::cached_resolve::CachedResolveLC3::boxed,
"cached_resolve"
);
#[cfg(feature = "instruction_mem")]
bench_new!(
lc3sim_project::executors::instruction_mem::InstMemLC3::boxed,
"instruction_mem"
);
}

pub fn load_os(c: &mut Criterion) {
let mut c = c.benchmark_group("load_os");

fn exec_setup<E: LC3>(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"
);
#[cfg(feature = "cached_resolve")]
bench_load!(
lc3sim_project::executors::cached_resolve::CachedResolveLC3::boxed,
"cached_resolve"
);
#[cfg(feature = "instruction_mem")]
bench_load!(
lc3sim_project::executors::instruction_mem::InstMemLC3::boxed,
"instruction_mem"
);
}

pub fn tiny_loop(c: &mut Criterion) {
let mut c = c.benchmark_group("tiny_loop");
let c = c.measurement_time(Duration::from_secs(20));

fn exec_loop<E: LC3>(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"
);
#[cfg(feature = "cached_resolve")]
bench_loop!(
lc3sim_project::executors::cached_resolve::CachedResolveLC3::boxed(),
"cached_resolve"
);
#[cfg(feature = "instruction_mem")]
bench_loop!(
lc3sim_project::executors::instruction_mem::InstMemLC3::boxed(),
"instruction_mem"
);
}

criterion_group!(speed_compare, create_new, load_os, tiny_loop);
criterion_main!(speed_compare);
Binary file added penn_sim/lc3os.obj
Binary file not shown.
Loading
Loading