From 13547e973cbaa6e69e3ac47ab10e81e6c45c52d4 Mon Sep 17 00:00:00 2001 From: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:48:18 +0200 Subject: [PATCH] Change message for identical time and add test for it --- src/benchmark/scheduler.rs | 31 +++++++++++++++++++++---------- tests/integration_tests.rs | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index c8ab49b..a88cda7 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -96,19 +96,30 @@ impl<'a> Scheduler<'a> { ); for item in others { + let stddev = if let Some(stddev) = item.relative_speed_stddev { + format!(" ± {}", format!("{:.2}", stddev).green()) + } else { + "".into() + }; let comparator = match item.relative_ordering { - Ordering::Less => "slower", - Ordering::Greater => "faster", - Ordering::Equal => "as fast", + Ordering::Less => format!( + "{}{} times slower than", + format!("{:8.2}", item.relative_speed).bold().green(), + stddev + ), + Ordering::Greater => format!( + "{}{} times faster than", + format!("{:8.2}", item.relative_speed).bold().green(), + stddev + ), + Ordering::Equal => format!( + " As fast ({}{}) as", + format!("{:.2}", item.relative_speed).bold().green(), + stddev + ), }; println!( - "{}{} times {} than {}", - format!("{:8.2}", item.relative_speed).bold().green(), - if let Some(stddev) = item.relative_speed_stddev { - format!(" ± {}", format!("{stddev:.2}").green()) - } else { - "".into() - }, + "{} {}", comparator, &item.result.command_with_unused_parameters.magenta() ); diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 3a58237..873f400 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -461,6 +461,24 @@ fn shows_benchmark_comparison_with_relative_times() { ); } +#[test] +fn shows_benchmark_comparison_with_same_time() { + hyperfine_debug() + .arg("--command-name=A") + .arg("--command-name=B") + .arg("sleep 1.0") + .arg("sleep 1.0") + .arg("sleep 2.0") + .arg("sleep 1000.0") + .assert() + .success() + .stdout( + predicate::str::contains("As fast (1.00 ± 0.00) as") + .and(predicate::str::contains("2.00 ± 0.00 times faster")) + .and(predicate::str::contains("1000.00 ± 0.00 times faster")), + ); +} + #[test] fn shows_benchmark_comparison_relative_to_reference() { hyperfine_debug()