Skip to content

Commit ff68c18

Browse files
committed
Set up codspeed benching
1 parent 51d3ddb commit ff68c18

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

.github/workflows/codspeed.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CodSpeed
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
# `workflow_dispatch` allows CodSpeed to trigger backtest
9+
# performance analysis in order to generate initial data.
10+
workflow_dispatch:
11+
12+
jobs:
13+
benchmarks:
14+
name: Run benchmarks
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Setup rust toolchain, cache and cargo-codspeed binary
20+
uses: moonrepo/setup-rust@v1
21+
with:
22+
cache-target: release
23+
bins: cargo-codspeed, aoc-cli
24+
25+
- name: Download available input files
26+
env:
27+
ADVENT_OF_CODE_SESSION: ${{ secrets.AOC_SESSION }}
28+
run: |
29+
mkdir -p inputs
30+
for i in {1..25}; do
31+
aoc download -I -i input/2024/day$i.txt --year 2024 -d $i || true
32+
done
33+
- name: Build the benchmark target(s)
34+
run: cargo codspeed build
35+
36+
- name: Run the benchmarks
37+
uses: CodSpeedHQ/action@v3
38+
with:
39+
run: cargo codspeed run
40+
token: ${{ secrets.CODSPEED_TOKEN }}

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ tinyvec = "1.8.0"
1717

1818
[dev-dependencies]
1919
criterion = { version = "2.7.2", package = "codspeed-criterion-compat" }
20+
indoc = "2.0.5"
21+
paste = "1.0.15"
22+
23+
[[bench]]
24+
name = "bench_days"
25+
harness = false

benches/bench_days.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use paste::paste;
3+
4+
/// Get input for a single day
5+
macro_rules! get_day_input {
6+
($day_num:literal) => {
7+
include_str!(concat!("../input/2024/day", $day_num, ".txt"))
8+
};
9+
}
10+
11+
/// Define benchmarks for a single day with part1 and part2
12+
macro_rules! benches_day {
13+
($day_num:literal) => {
14+
paste! {
15+
use advent_of_code_2024::[<day $day_num>]; // Replace `aoc24` with your crate name
16+
17+
pub fn [<bench_day $day_num>](c: &mut Criterion) {
18+
let mut group = c.benchmark_group(concat!("day", $day_num));
19+
let input = get_day_input!($day_num);
20+
group.bench_function(format!("day{}_part1", $day_num), |b| b.iter(|| [<day $day_num>]::part1(input)));
21+
group.bench_function(format!("day{}_part2", $day_num), |b| b.iter(|| [<day $day_num>]::part2(input)));
22+
}
23+
}
24+
};
25+
}
26+
27+
/// Create benchmarks for included days
28+
macro_rules! benches {
29+
($($day_num:literal),*) => {
30+
paste! {
31+
$(
32+
benches_day!($day_num);
33+
)*
34+
35+
criterion_group!(benches, $([<bench_day $day_num>]),*);
36+
criterion_main!(benches);
37+
}
38+
};
39+
}
40+
41+
benches!(6);

0 commit comments

Comments
 (0)