diff --git a/src/benchmark.rs b/src/benchmark.rs index 5a05269..7f0d1e9 100644 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -391,7 +391,10 @@ pub fn run_benchmark( // Compute statistical quantities let t_num = times_real.len(); let t_mean = mean(×_real); - let t_stddev = standard_deviation(×_real, Some(t_mean)); + let mut t_stddev = 0.0; + if times_real.len() != 1 { + t_stddev = standard_deviation(×_real, Some(t_mean)); + } let t_median = median(×_real); let t_min = min(×_real); let t_max = max(×_real); @@ -409,7 +412,16 @@ pub fn run_benchmark( let user_str = format_duration(user_mean, Some(time_unit)); let system_str = format_duration(system_mean, Some(time_unit)); - if options.output_style != OutputStyleOption::Disabled { + if options.output_style != OutputStyleOption::Disabled && times_real.len() == 1 { + println!( + " Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]", + "abs".green().bold(), + mean_str.green().bold(), + " ".to_string(), // alignment + user_str.blue(), + system_str.blue() + ); + } else if options.output_style != OutputStyleOption::Disabled { println!( " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]", "mean".green().bold(), diff --git a/src/error.rs b/src/error.rs index 298b310..8e892db 100644 --- a/src/error.rs +++ b/src/error.rs @@ -57,7 +57,6 @@ impl Error for ParameterScanError {} #[derive(Debug)] pub enum OptionsError<'a> { - RunsBelowTwo, EmptyRunsRange, TooManyCommandNames(usize), UnexpectedCommandNameCount(usize, usize), @@ -70,7 +69,6 @@ impl<'a> fmt::Display for OptionsError<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { OptionsError::EmptyRunsRange => write!(f, "Empty runs range"), - OptionsError::RunsBelowTwo => write!(f, "Number of runs below two"), OptionsError::TooManyCommandNames(n) => { write!(f, "Too many --command-name options: expected {} at most", n) } diff --git a/src/main.rs b/src/main.rs index b0521fb..63c87bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,17 +171,9 @@ fn build_hyperfine_options<'a>( } match (min_runs, max_runs) { - (Some(min), _) if min < 2 => { - // We need at least two runs to compute a variance. - return Err(OptionsError::RunsBelowTwo); - } (Some(min), None) => { options.runs.min = min; } - (_, Some(max)) if max < 2 => { - // We need at least two runs to compute a variance. - return Err(OptionsError::RunsBelowTwo); - } (None, Some(max)) => { // Since the minimum was not explicit we lower it if max is below the default min. options.runs.min = cmp::min(options.runs.min, max); diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 8328f06..ae502fc 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -23,12 +23,12 @@ fn hyperfine_runs_successfully() { } #[test] -fn at_least_two_runs_are_required() { +fn one_run_is_supported() { hyperfine() .arg("--runs=1") .arg("echo dummy benchmark") .assert() - .failure(); + .success(); } struct ExecutionOrderTest { @@ -109,6 +109,17 @@ impl Default for ExecutionOrderTest { } } +#[test] +fn benchmarks_are_executed_sequentially_one() { + ExecutionOrderTest::new() + .arg("--runs=1") + .command("command 1") + .command("command 2") + .expect_output("command 1") + .expect_output("command 2") + .run(); +} + #[test] fn benchmarks_are_executed_sequentially() { ExecutionOrderTest::new()