Skip to content

Commit 47b1a38

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 47b1a38

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
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("Gives 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

+13-2
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,22 @@ fn shows_benchmark_comparison_relative_to_reference() {
494494
.assert()
495495
.success()
496496
.stdout(
497-
predicate::str::contains("2.00 ± 0.00 times slower")
498-
.and(predicate::str::contains("1.50 ± 0.00 times faster")),
497+
predicate::str::contains("").and(predicate::str::contains("1.50 ± 0.00 times faster")),
499498
);
500499
}
501500

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

0 commit comments

Comments
 (0)