Skip to content

Commit 2934163

Browse files
committed
Add missing black_box for bench_with_input parameters. Fixes 566.
1 parent ecfd1d1 commit 2934163

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3131
- Formal support for benchmarking code compiled to web-assembly.
3232
- A `--quiet` flag for printing just a single line per benchmark.
3333

34+
### Fixed
35+
- When using `bench_with_input`, the input parameter will now be passed through `black_box` before
36+
passing it to the benchmark.
37+
3438
## [0.3.5] - 2021-07-26
3539

3640
### Fixed

src/routine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::benchmark::BenchmarkConfig;
22
use crate::connection::OutgoingMessage;
33
use crate::measurement::Measurement;
44
use crate::report::{BenchmarkId, Report, ReportContext};
5-
use crate::{ActualSamplingMode, Bencher, Criterion};
5+
use crate::{black_box, ActualSamplingMode, Bencher, Criterion};
66
use std::marker::PhantomData;
77
use std::time::Duration;
88

@@ -247,7 +247,7 @@ where
247247
.iter()
248248
.map(|iters| {
249249
b.iters = *iters;
250-
(*f)(&mut b, parameter);
250+
(*f)(&mut b, black_box(parameter));
251251
b.assert_iterated();
252252
m.to_f64(&b.value)
253253
})
@@ -267,7 +267,7 @@ where
267267
let mut total_iters = 0;
268268
let mut elapsed_time = Duration::from_millis(0);
269269
loop {
270-
(*f)(&mut b, parameter);
270+
(*f)(&mut b, black_box(parameter));
271271

272272
b.assert_iterated();
273273

0 commit comments

Comments
 (0)