Skip to content

Commit fbea5fc

Browse files
committed
More closly resembly real benching setup
1 parent a493348 commit fbea5fc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

benches/bench_days.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use paste::paste;
3+
use std::{fmt::Display, hint::black_box};
34

45
/// Get input for a single day
56
macro_rules! get_day_input {
@@ -17,8 +18,17 @@ macro_rules! benches_day {
1718
pub fn [<bench_day $day_num>](c: &mut Criterion) {
1819
let mut group = c.benchmark_group(concat!("day", $day_num));
1920
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)));
21+
22+
#[inline(never)]
23+
fn routine_part1(input: &str) -> impl Display + '_ {
24+
[<day $day_num>]::part1(black_box(input))
25+
}
26+
group.bench_with_input(format!("day{}_part1", $day_num), input, |b, i| b.iter(|| routine_part1(i)));
27+
#[inline(never)]
28+
fn routine_part2(input: &str) -> impl Display + '_ {
29+
[<day $day_num>]::part2(black_box(input))
30+
}
31+
group.bench_with_input(format!("day{}_part2", $day_num), input, |b, i| b.iter(|| routine_part2(i)));
2232
}
2333
}
2434
};

0 commit comments

Comments
 (0)