Skip to content

Commit c241820

Browse files
authored
feat: use hint::black_box for benchmark evaluation (#47)
* this prevents cases where subsequent invocations of a solution fully unroll it, leading to deceivingly low execution times being reported.
1 parent a9dcd18 commit c241820

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: src/template/runner.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Encapsulates code that interacts with solution functions.
22
use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET};
33
use std::fmt::Display;
4+
use std::hint::black_box;
45
use std::io::{stdout, Write};
56
use std::process::Output;
67
use std::time::{Duration, Instant};
@@ -64,7 +65,7 @@ fn bench<I: Clone, T>(func: impl Fn(I) -> T, input: I, base_time: &Duration) ->
6465
// need a clone here to make the borrow checker happy.
6566
let cloned = input.clone();
6667
let timer = Instant::now();
67-
func(cloned);
68+
black_box(func(black_box(cloned)));
6869
timers.push(timer.elapsed());
6970
}
7071

0 commit comments

Comments
 (0)