-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CodSpeed | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
# `workflow_dispatch` allows CodSpeed to trigger backtest | ||
# performance analysis in order to generate initial data. | ||
workflow_dispatch: | ||
|
||
jobs: | ||
benchmarks: | ||
name: Run benchmarks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup rust toolchain, cache and cargo-codspeed binary | ||
uses: moonrepo/setup-rust@v1 | ||
with: | ||
cache-target: release | ||
bins: cargo-codspeed, aoc-cli | ||
|
||
- name: Download available input files | ||
env: | ||
ADVENT_OF_CODE_SESSION: ${{ secrets.AOC_SESSION }} | ||
run: | | ||
mkdir -p inputs | ||
for i in {1..25}; do | ||
aoc download -I -i input/2024/day$i.txt --year 2024 -d $i || true | ||
done | ||
- name: Build the benchmark target(s) | ||
run: cargo codspeed build | ||
|
||
- name: Run the benchmarks | ||
uses: CodSpeedHQ/action@v3 | ||
with: | ||
run: cargo codspeed run | ||
token: ${{ secrets.CODSPEED_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use paste::paste; | ||
|
||
/// Get input for a single day | ||
macro_rules! get_day_input { | ||
($day_num:literal) => { | ||
include_str!(concat!("../input/2024/day", $day_num, ".txt")) | ||
}; | ||
} | ||
|
||
/// Define benchmarks for a single day with part1 and part2 | ||
macro_rules! benches_day { | ||
($day_num:literal) => { | ||
paste! { | ||
use advent_of_code_2024::[<day $day_num>]; // Replace `aoc24` with your crate name | ||
|
||
pub fn [<bench_day $day_num>](c: &mut Criterion) { | ||
let mut group = c.benchmark_group(concat!("day", $day_num)); | ||
let input = get_day_input!($day_num); | ||
group.bench_function(format!("day{}_part1", $day_num), |b| b.iter(|| [<day $day_num>]::part1(input))); | ||
group.bench_function(format!("day{}_part2", $day_num), |b| b.iter(|| [<day $day_num>]::part2(input))); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/// Create benchmarks for included days | ||
macro_rules! benches { | ||
($($day_num:literal),*) => { | ||
paste! { | ||
$( | ||
benches_day!($day_num); | ||
)* | ||
|
||
criterion_group!(benches, $([<bench_day $day_num>]),*); | ||
criterion_main!(benches); | ||
} | ||
}; | ||
} | ||
|
||
benches!(6); |