From 2934163518a75bf037c7467c0a1d28443203eabf Mon Sep 17 00:00:00 2001 From: Brook Heisler Date: Thu, 14 Jul 2022 18:29:49 -0600 Subject: [PATCH] Add missing black_box for bench_with_input parameters. Fixes 566. --- CHANGELOG.md | 4 ++++ src/routine.rs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2eb6531..6b5a1153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Formal support for benchmarking code compiled to web-assembly. - A `--quiet` flag for printing just a single line per benchmark. +### Fixed +- When using `bench_with_input`, the input parameter will now be passed through `black_box` before + passing it to the benchmark. + ## [0.3.5] - 2021-07-26 ### Fixed diff --git a/src/routine.rs b/src/routine.rs index b4bb7c15..9567fb43 100644 --- a/src/routine.rs +++ b/src/routine.rs @@ -2,7 +2,7 @@ use crate::benchmark::BenchmarkConfig; use crate::connection::OutgoingMessage; use crate::measurement::Measurement; use crate::report::{BenchmarkId, Report, ReportContext}; -use crate::{ActualSamplingMode, Bencher, Criterion}; +use crate::{black_box, ActualSamplingMode, Bencher, Criterion}; use std::marker::PhantomData; use std::time::Duration; @@ -247,7 +247,7 @@ where .iter() .map(|iters| { b.iters = *iters; - (*f)(&mut b, parameter); + (*f)(&mut b, black_box(parameter)); b.assert_iterated(); m.to_f64(&b.value) }) @@ -267,7 +267,7 @@ where let mut total_iters = 0; let mut elapsed_time = Duration::from_millis(0); loop { - (*f)(&mut b, parameter); + (*f)(&mut b, black_box(parameter)); b.assert_iterated();