From 0f56c84d4e5f85aa13520c67b189c6e40362a5c1 Mon Sep 17 00:00:00 2001 From: Niklas Dewally Date: Sat, 15 Mar 2025 19:45:41 +0000 Subject: [PATCH] Add option to name reference command Add --reference-name option to give a reference command a name. This was discussed in the PR that added --reference, #744, but was unfortunately never implemented. --- src/benchmark/scheduler.rs | 2 +- src/cli.rs | 8 ++++++++ src/options.rs | 7 +++++++ tests/integration_tests.rs | 12 ++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index f56910872..242dd0e7d 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -42,7 +42,7 @@ impl<'a> Scheduler<'a> { .options .reference_command .as_ref() - .map(|cmd| Command::new(None, cmd)); + .map(|cmd| Command::new(self.options.reference_name.as_deref(), cmd)); executor.calibrate()?; diff --git a/src/cli.rs b/src/cli.rs index 5dbc56799..eceabcb6c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -96,6 +96,14 @@ fn build_command() -> Command { If this is unset, results are compared with the fastest command as reference." ) ) + .arg( + Arg::new("reference-name") + .long("reference-name") + .action(ArgAction::Set) + .value_name("CMD") + .help("Give a meaningful name to the reference command.") + .requires("reference") + ) .arg( Arg::new("prepare") .long("prepare") diff --git a/src/options.rs b/src/options.rs index c4cffc3ff..38f9b2c90 100644 --- a/src/options.rs +++ b/src/options.rs @@ -208,6 +208,9 @@ pub struct Options { // Command to use as a reference for relative speed comparison pub reference_command: Option, + // Name of the reference command + pub reference_name: Option, + /// Command(s) to run before each timing run pub preparation_command: Option>, @@ -250,6 +253,7 @@ impl Default for Options { min_benchmarking_time: 3.0, command_failure_action: CmdFailureAction::RaiseError, reference_command: None, + reference_name: None, preparation_command: None, conclusion_command: None, setup_command: None, @@ -310,6 +314,9 @@ impl Options { options.setup_command = matches.get_one::("setup").map(String::from); options.reference_command = matches.get_one::("reference").map(String::from); + options.reference_name = matches + .get_one::("reference-name") + .map(String::from); options.preparation_command = matches .get_many::("prepare") diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 4efe20c63..467280858 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -499,6 +499,18 @@ fn shows_benchmark_comparison_relative_to_reference() { ); } +#[test] +fn shows_reference_name() { + hyperfine_debug() + .arg("--reference=sleep 2.0") + .arg("--reference-name=refabc123") + .arg("sleep 1.0") + .arg("sleep 3.0") + .assert() + .success() + .stdout(predicate::str::contains("Benchmark 1: refabc123")); +} + #[test] fn performs_all_benchmarks_in_parameter_scan() { hyperfine_debug()