Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c241820

Browse files
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

‎src/template/runner.rs‎

Lines changed: 2 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /