From ba65dd8c4e893bb9cdc4b959922ce2b62f6d96b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=B6ttel?= <1682504+fspoettel@users.noreply.github.com> Date: Wed, 6 Dec 2023 09:36:34 +0100 Subject: [PATCH] feat: use black_boxes for benchmark evaluation --- src/template/runner.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/template/runner.rs b/src/template/runner.rs index 00637bb..4b47332 100644 --- a/src/template/runner.rs +++ b/src/template/runner.rs @@ -1,6 +1,7 @@ /// Encapsulates code that interacts with solution functions. use crate::template::{aoc_cli, Day, ANSI_ITALIC, ANSI_RESET}; use std::fmt::Display; +use std::hint::black_box; use std::io::{stdout, Write}; use std::process::Output; use std::time::{Duration, Instant}; @@ -64,7 +65,7 @@ fn bench(func: impl Fn(I) -> T, input: I, base_time: &Duration) -> // need a clone here to make the borrow checker happy. let cloned = input.clone(); let timer = Instant::now(); - func(cloned); + black_box(func(black_box(cloned))); timers.push(timer.elapsed()); }