Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/benchmark/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,46 @@ impl<'a> Scheduler<'a> {
SortOrder::Command => {
println!("{}", "Relative speed comparison".bold());

let show_reference_annotations = self.options.reference_command.is_some();
let reference_command = if show_reference_annotations {
annotated_results
.iter()
.find(|r| r.is_reference)
.map(|r| r.result.command_with_unused_parameters.as_str())
} else {
None
};

for item in annotated_results {
let stddev_suffix = if item.is_reference {
" ".into()
} else if let Some(stddev) = item.relative_speed_stddev {
format!(" ± {}", format!("{stddev:5.2}").green())
} else {
" ".into()
};

let reference_annotation =
if show_reference_annotations && !item.is_reference {
let reference_command = reference_command.unwrap();
match item.relative_ordering {
Ordering::Less => {
format!(" times faster than {reference_command}")
}
Ordering::Greater => {
format!(" times slower than {reference_command}")
}
Ordering::Equal => format!(" as fast as {reference_command}"),
}
} else {
String::new()
};

println!(
" {}{} {}",
" {}{}{} {}",
format!("{:10.2}", item.relative_speed).bold().green(),
if item.is_reference {
" ".into()
} else if let Some(stddev) = item.relative_speed_stddev {
format!(" ± {}", format!("{stddev:5.2}").green())
} else {
" ".into()
},
stddev_suffix,
reference_annotation,
&item.result.command_with_unused_parameters,
);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,22 @@ fn shows_reference_name() {
.stdout(predicate::str::contains("Benchmark 1: refabc123"));
}

#[test]
fn shows_faster_slower_annotations_with_sort_command_and_reference() {
hyperfine_debug()
.arg("--sort=command")
.arg("--reference=sleep 2.0")
.arg("sleep 1.0")
.arg("sleep 3.0")
.assert()
.success()
.stdout(
predicate::str::contains("Relative speed comparison")
.and(predicate::str::contains("times faster than sleep 2.0"))
.and(predicate::str::contains("times slower than sleep 2.0")),
);
}

#[test]
fn performs_all_benchmarks_in_parameter_scan() {
hyperfine_debug()
Expand Down