Skip to content

Commit 0f56c84

Browse files
committed
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.
1 parent 3cedcc3 commit 0f56c84

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/benchmark/scheduler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a> Scheduler<'a> {
4242
.options
4343
.reference_command
4444
.as_ref()
45-
.map(|cmd| Command::new(None, cmd));
45+
.map(|cmd| Command::new(self.options.reference_name.as_deref(), cmd));
4646

4747
executor.calibrate()?;
4848

src/cli.rs

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ fn build_command() -> Command {
9696
If this is unset, results are compared with the fastest command as reference."
9797
)
9898
)
99+
.arg(
100+
Arg::new("reference-name")
101+
.long("reference-name")
102+
.action(ArgAction::Set)
103+
.value_name("CMD")
104+
.help("Give a meaningful name to the reference command.")
105+
.requires("reference")
106+
)
99107
.arg(
100108
Arg::new("prepare")
101109
.long("prepare")

src/options.rs

+7
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ pub struct Options {
208208
// Command to use as a reference for relative speed comparison
209209
pub reference_command: Option<String>,
210210

211+
// Name of the reference command
212+
pub reference_name: Option<String>,
213+
211214
/// Command(s) to run before each timing run
212215
pub preparation_command: Option<Vec<String>>,
213216

@@ -250,6 +253,7 @@ impl Default for Options {
250253
min_benchmarking_time: 3.0,
251254
command_failure_action: CmdFailureAction::RaiseError,
252255
reference_command: None,
256+
reference_name: None,
253257
preparation_command: None,
254258
conclusion_command: None,
255259
setup_command: None,
@@ -310,6 +314,9 @@ impl Options {
310314
options.setup_command = matches.get_one::<String>("setup").map(String::from);
311315

312316
options.reference_command = matches.get_one::<String>("reference").map(String::from);
317+
options.reference_name = matches
318+
.get_one::<String>("reference-name")
319+
.map(String::from);
313320

314321
options.preparation_command = matches
315322
.get_many::<String>("prepare")

tests/integration_tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ fn shows_benchmark_comparison_relative_to_reference() {
499499
);
500500
}
501501

502+
#[test]
503+
fn shows_reference_name() {
504+
hyperfine_debug()
505+
.arg("--reference=sleep 2.0")
506+
.arg("--reference-name=refabc123")
507+
.arg("sleep 1.0")
508+
.arg("sleep 3.0")
509+
.assert()
510+
.success()
511+
.stdout(predicate::str::contains("Benchmark 1: refabc123"));
512+
}
513+
502514
#[test]
503515
fn performs_all_benchmarks_in_parameter_scan() {
504516
hyperfine_debug()

0 commit comments

Comments
 (0)