Macro-ify benches and unify days list to one file

Also update README with new options.
This commit is contained in:
2025-12-03 01:22:09 -05:00
parent cdc0225ca8
commit 5433430628
5 changed files with 41 additions and 20 deletions

View File

@@ -6,13 +6,17 @@ Rusty and over-engineered edition.
By request of AoC creator, I haven't included the input files (e.g. src/input/day01.txt). Log into the Advent of Code site and save the inputs there to the src/input/ folder.
Then to run: `cargo run`.
To run all days: `cargo run`.
To run a specific day and/or part: `cargo run -- --day 1 --part 1`.
To run in super-fast prod mode: `cargo run --release`.
To run with debug logs enabled: `RUST_LOG=debug cargo run`.
To run the tests against included test input files: `RUST_LOG=debug cargo test -- --no-capture`.
To run all the tests against included test input files: `RUST_LOG=debug cargo test -- --no-capture`.
To run the tests for a specific day and/or part: `RUST_LOG=debug cargo test day01::test::test_part1 -- --no-capture`.
## Benchmarks

View File

@@ -1,16 +1,23 @@
use aoc::day01;
use aoc::day02;
use criterion::{Criterion, criterion_group, criterion_main};
fn day01_benchmark(c: &mut Criterion) {
c.bench_function("day01 part1", |b| b.iter(|| day01::part1(day01::INPUT)));
c.bench_function("day01 part2", |b| b.iter(|| day01::part2(day01::INPUT)));
}
macro_rules! bench_days {
($($day_num:literal => $day_mod:ident),* $(,)?) => {
$(
use aoc::$day_mod;
fn day02_benchmark(c: &mut Criterion) {
c.bench_function("day02 part1", |b| b.iter(|| day02::part1(day02::INPUT)));
c.bench_function("day02 part2", |b| b.iter(|| day02::part2(day02::INPUT)));
fn $day_mod(c: &mut Criterion) {
c.bench_function(concat!(stringify!($day_mod), " part1"), |b| {
b.iter(|| $day_mod::part1($day_mod::INPUT))
});
c.bench_function(concat!(stringify!($day_mod), " part2"), |b| {
b.iter(|| $day_mod::part2($day_mod::INPUT))
});
}
)*
criterion_group!(benches, day01_benchmark, day02_benchmark);
criterion_group!(benches, $($day_mod),*);
criterion_main!(benches);
};
}
aoc::all_days!(bench_days);

12
src/days.rs Normal file
View File

@@ -0,0 +1,12 @@
// Single source of truth for all implemented days
// Add new days here and they'll automatically be available in both the runner and benchmarks
#[macro_export]
macro_rules! all_days {
($macro_name:path) => {
$macro_name! {
1 => day01,
2 => day02,
}
};
}

View File

@@ -1,2 +1,3 @@
pub mod day01;
pub mod day02;
pub mod days;

View File

@@ -1,7 +1,7 @@
mod days;
mod runner;
pub mod day01;
pub mod day02;
use aoc::{day01, day02};
use clap::Parser;
use color_eyre::Result;
@@ -24,10 +24,7 @@ struct Args {
part: Option<u8>,
}
runner::days! {
1 => day01,
2 => day02,
}
all_days!(runner::days);
fn main() -> Result<()> {
color_eyre::install()?;