Closed
Description
#[bench]
functions are run multiple times. Some benchmark functions might depend on some runtime initialisation which may fail. For example:
#[bench]
fn bench_this(b : &mut Bencher) {
if let Ok(val) = WillFailOnEvenHour::new() {
b.iter(||{ var.current_hour_is_not_even() });
} else {
// nothing to bench here? Maybe print an error?
println!("Benchmarks on even hours are forbidden!");
}
}
Will print “Benchmarks on even hours are forbidden!” a lot of times. If one opts to not report set-up failure, the benchmark function just keeps processor hot for a while without actually benchmarking anything (and reporting 0ns/iter anyway).
Would it be sensible to (one of possible solutions):
- Not run the same
#[bench]
function multiple times, since iteration is done by.iter
; - Not run the same
#[bench]
again ifBencher::iter
is not called at least once; - Provide a method on
Bencher
to cancel all subsequent runs of the#[bench]
function?
Or maybe my approach is incorrect?
Metadata
Metadata
Assignees
Labels
No labels