From 74cb6b07abe812a9ec5d721c7890451a59ac26c3 Mon Sep 17 00:00:00 2001 From: pederbe Date: Sat, 5 Sep 2026 18:16:30 +0200 Subject: [PATCH] Clarify reference comparisons when sorting by command --- src/benchmark/scheduler.rs | 20 +++++++++++++++++++- tests/integration_tests.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index 242dd0e7d..32510e77b 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -125,8 +125,21 @@ impl<'a> Scheduler<'a> { println!("{}", "Relative speed comparison".bold()); for item in annotated_results { + let comparison = if self.options.reference_command.is_some() { + if item.is_reference { + "reference" + } else { + match item.relative_ordering { + Ordering::Less => "times faster than reference", + Ordering::Greater => "times slower than reference", + Ordering::Equal => "as fast as reference", + } + } + } else { + "" + }; println!( - " {}{} {}", + " {}{} {}{}", format!("{:10.2}", item.relative_speed).bold().green(), if item.is_reference { " ".into() @@ -135,6 +148,11 @@ impl<'a> Scheduler<'a> { } else { " ".into() }, + if comparison.is_empty() { + String::new() + } else { + format!("{comparison:28} ") + }, &item.result.command_with_unused_parameters, ); } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 2de3a5049..c43c7e144 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -583,6 +583,42 @@ fn shows_reference_name() { .stdout(predicate::str::contains("Benchmark 1: refabc123")); } +#[test] +fn command_sorted_comparison_labels_reference_and_direction() { + for runs in ["1", "2"] { + let output = hyperfine_debug() + .args(["--runs", runs, "--sort=command"]) + .args(["--reference=sleep 2", "--reference-name=baseline"]) + .args([ + "--command-name=slower", + "--command-name=faster", + "--command-name=equal", + ]) + .args(["sleep 3", "sleep 1", "sleep 2"]) + .assert() + .success() + .get_output() + .stdout + .clone(); + let output = String::from_utf8(output).unwrap(); + let comparison = output.split("Relative speed comparison\n").nth(1).unwrap(); + let lines: Vec<_> = comparison + .lines() + .map(|line| line.split_whitespace().collect::>().join(" ")) + .collect(); + let uncertainty = if runs == "2" { " ± 0.00" } else { "" }; + assert_eq!( + lines, + vec![ + "1.00 reference baseline".to_string(), + format!("1.50{uncertainty} times slower than reference slower"), + format!("2.00{uncertainty} times faster than reference faster"), + format!("1.00{uncertainty} as fast as reference equal"), + ] + ); + } +} + #[test] fn performs_all_benchmarks_in_parameter_scan() { hyperfine_debug()