add CLI option to identify a command with a custom name

CLI option `--name` can be used to define the name to identify a
command. If not passed, then the command itself is used. Commands
and names are paired in the same order: The first command executed gets
the first name passed as option.

Close #326
This commit is contained in:
Stéphane Campinas authored and David Peter committed 2020-10-15 22:42:44 +02:00
1 parent 674b5422ab
commit 0f0a109ca0
4 files changed
+27 -2

No files matched your search

+10 -2
View File
@@ -202,12 +202,20 @@ pub fn run_benchmark(
shell_spawning_time: TimingResult,
options: &HyperfineOptions,
) -> io::Result<BenchmarkResult> {
let shell_cmd = cmd.get_shell_command();
let command_name = if let Some(names) = &options.names {
names.get(num).unwrap_or(&shell_cmd)
} else {
&shell_cmd
};
let command_name = command_name.to_string();
if options.output_style != OutputStyleOption::Disabled {
println!(
"{}{}: {}",
"Benchmark #".bold(),
(num + 1).to_string().bold(),
cmd
&command_name
);
}
@@ -415,7 +423,7 @@ pub fn run_benchmark(
run_cleanup_command(&options.shell, &cleanup_cmd, options.show_output)?;
Ok(BenchmarkResult::new(
cmd.get_shell_command(),
command_name,
t_mean,
t_stddev,
t_median,