Macro-ify benches and unify days list to one file
Also update README with new options.
This commit is contained in:
@@ -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.
|
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 in super-fast prod mode: `cargo run --release`.
|
||||||
|
|
||||||
To run with debug logs enabled: `RUST_LOG=debug cargo run`.
|
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
|
## Benchmarks
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
use aoc::day01;
|
|
||||||
use aoc::day02;
|
|
||||||
use criterion::{Criterion, criterion_group, criterion_main};
|
use criterion::{Criterion, criterion_group, criterion_main};
|
||||||
|
|
||||||
fn day01_benchmark(c: &mut Criterion) {
|
macro_rules! bench_days {
|
||||||
c.bench_function("day01 part1", |b| b.iter(|| day01::part1(day01::INPUT)));
|
($($day_num:literal => $day_mod:ident),* $(,)?) => {
|
||||||
c.bench_function("day01 part2", |b| b.iter(|| day01::part2(day01::INPUT)));
|
$(
|
||||||
|
use aoc::$day_mod;
|
||||||
|
|
||||||
|
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, $($day_mod),*);
|
||||||
|
criterion_main!(benches);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn day02_benchmark(c: &mut Criterion) {
|
aoc::all_days!(bench_days);
|
||||||
c.bench_function("day02 part1", |b| b.iter(|| day02::part1(day02::INPUT)));
|
|
||||||
c.bench_function("day02 part2", |b| b.iter(|| day02::part2(day02::INPUT)));
|
|
||||||
}
|
|
||||||
|
|
||||||
criterion_group!(benches, day01_benchmark, day02_benchmark);
|
|
||||||
criterion_main!(benches);
|
|
||||||
|
|||||||
12
src/days.rs
Normal file
12
src/days.rs
Normal 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,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod day01;
|
pub mod day01;
|
||||||
pub mod day02;
|
pub mod day02;
|
||||||
|
pub mod days;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
mod days;
|
||||||
mod runner;
|
mod runner;
|
||||||
|
|
||||||
pub mod day01;
|
use aoc::{day01, day02};
|
||||||
pub mod day02;
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
@@ -24,10 +24,7 @@ struct Args {
|
|||||||
part: Option<u8>,
|
part: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
runner::days! {
|
all_days!(runner::days);
|
||||||
1 => day01,
|
|
||||||
2 => day02,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user