Skip to content

Commit

Permalink
add iai benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Dec 7, 2024
1 parent e5811a3 commit 0976140
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 134 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ jobs:
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run benchmarks
run: cargo bench
- name: Run criterion benchmarks
run: cargo bench criterion
env:
AOC_SESSION: ${{secrets.AOC_SESSION}}
# Run iai after criterion to ensure private solutions have been downloaded,
# since the iai version cannot be built without private inputs.
- name: Run iai
run: cargo bench iai --features iai-bench
- name: Publish results
id: deployment
uses: actions/upload-pages-artifact@v3
Expand Down
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
members = [".", "macros"]

[package]
name = "aoc2024"
version = "0.1.0"
Expand All @@ -7,17 +10,29 @@ edition = "2021"
anyhow = "1.0.93"
bitvec = "1.0.1"
clap = { version = "4.5.21", features = ["derive"] }
criterion = "0.5.1"
itertools = "0.13.0"
jq-rs = { version = "0.4.1", features = ["bundled"] }
paste = "1.0.15"
reqwest = { version = "0.12.9", features = ["blocking"] }
rustc-hash = "2.1.0"
simd-json = "0.14.3"
macros = { path = "macros" }

[patch.crates-io]
jq-src = { git = "https://github.com/SOF3/jq-src", rev = "refs/tags/jq-1.7.1" }

[dev-dependencies]
criterion = "0.5.1"
iai = "0.1.1"

[[bench]]
name = "main"
name = "criterion"
harness = false

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


[features]
iai-bench = []
22 changes: 22 additions & 0 deletions benches/criterion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fmt;

use aoc2024::*;
use criterion::*;

fn bench(criterion_manager: &mut Criterion) {
fn run(criterion_manager: &mut Criterion) -> anyhow::Result<()> {
aoc2024::bench!(criterion_manager);
Ok(())
}

run(criterion_manager).unwrap();
}

fn call_benched<In: Parse, Out: fmt::Display>(b: &mut Bencher, day: u32, f: impl FnMut(In) -> Out) {
let input = load_input(Mode::Private, day).unwrap();
let parsed: In = Parse::parse(&input);
b.iter_batched(|| parsed.clone(), f, BatchSize::LargeInput);
}

criterion_group!(benches, bench);
criterion_main!(benches);
5 changes: 5 additions & 0 deletions benches/iai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "iai-bench")]
aoc2024::iai!();

Check failure on line 2 in benches/iai.rs

View workflow job for this annotation

GitHub Actions / run benchmark

couldn't read `/home/runner/work/aoc2024/aoc2024/input/d1.private.input.txt`: No such file or directory (os error 2)

Check failure on line 2 in benches/iai.rs

View workflow job for this annotation

GitHub Actions / run benchmark

couldn't read `/home/runner/work/aoc2024/aoc2024/input/d2.private.input.txt`: No such file or directory (os error 2)

Check failure on line 2 in benches/iai.rs

View workflow job for this annotation

GitHub Actions / run benchmark

couldn't read `/home/runner/work/aoc2024/aoc2024/input/d3.private.input.txt`: No such file or directory (os error 2)

Check failure on line 2 in benches/iai.rs

View workflow job for this annotation

GitHub Actions / run benchmark

couldn't read `/home/runner/work/aoc2024/aoc2024/input/d4.private.input.txt`: No such file or directory (os error 2)

Check failure on line 2 in benches/iai.rs

View workflow job for this annotation

GitHub Actions / run benchmark

couldn't read `/home/runner/work/aoc2024/aoc2024/input/d5.private.input.txt`: No such file or directory (os error 2)

#[cfg(not(feature = "iai-bench"))]
fn main() {}
4 changes: 0 additions & 4 deletions benches/main.rs

This file was deleted.

13 changes: 13 additions & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "macros"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
itertools = "0.13.0"
proc-macro2 = "1.0.92"
quote = "1.0.37"
syn = "2.0.90"
Loading

0 comments on commit 0976140

Please sign in to comment.