Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,18 @@ impl<'a> Benchmark<'a> {
let count = {
let min = cmp::max(runs_in_min_time, self.options.run_bounds.min);

self.options
let count = self
.options
.run_bounds
.max
.as_ref()
.map(|max| cmp::min(min, *max))
.unwrap_or(min)
.unwrap_or(min);

// The initial timing run above has already been performed, so we can never
// end up with fewer than one run (this could happen with '--min-runs 0' for
// a command that is slower than the minimum benchmarking time).
cmp::max(count, 1)
};

let count_remaining = count - 1;
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub enum OptionsError<'a> {
"Conflicting requirements for the number of runs (empty range, min is larger than max)"
)]
EmptyRunsRange,
#[error(
"At least one run has to be performed. Please specify a value larger than zero for '--{0}'"
)]
ZeroRuns(&'a str),
#[error("Too many --command-name options: Expected {0} at most")]
TooManyCommandNames(usize),
#[error("'--command-name' has been specified {0} times. It has to appear exactly once, or exactly {1} times (number of benchmarks)")]
Expand Down
5 changes: 5 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,13 @@ impl Options {
let mut max_runs = param_to_u64("max-runs")?;

if let Some(runs) = param_to_u64("runs")? {
if runs == 0 {
return Err(OptionsError::ZeroRuns("runs"));
}
min_runs = Some(runs);
max_runs = Some(runs);
} else if max_runs == Some(0) {
return Err(OptionsError::ZeroRuns("max-runs"));
}

match (min_runs, max_runs) {
Expand Down
24 changes: 24 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ fn one_run_is_supported() {
.success();
}

#[test]
fn fails_with_zero_runs() {
for option in ["--runs=0", "--max-runs=0"] {
hyperfine()
.arg(option)
.arg("echo dummy benchmark")
.assert()
.failure()
.stderr(predicate::str::contains(
"At least one run has to be performed",
));
}
}

#[test]
fn min_runs_of_zero_still_performs_one_run() {
hyperfine_debug()
.arg("--min-runs=0")
.arg("sleep 4")
.assert()
.success()
.stdout(predicate::str::contains("Time (abs ≡)"));
}

#[test]
fn can_run_commands_without_a_shell() {
hyperfine()
Expand Down