Skip to content
Open
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
20 changes: 19 additions & 1 deletion src/benchmark/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>().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()
Expand Down