diff --git a/src/hyperfine/app.rs b/src/hyperfine/app.rs index 6421ab209..1521af821 100644 --- a/src/hyperfine/app.rs +++ b/src/hyperfine/app.rs @@ -226,6 +226,16 @@ fn build_app() -> App<'static, 'static> { when trying to benchmark output speed.", ), ) + .arg( + Arg::with_name("command-name") + .long("name") + .short("n") + .takes_value(true) + .multiple(true) + .number_of_values(1) + .value_name("NAME") + .help("Give a meaningful name to a command"), + ) .help_message("Print this help message.") .version_message("Show version information.") } diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index f2de69d8a..bb9d918de 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -202,12 +202,20 @@ pub fn run_benchmark( shell_spawning_time: TimingResult, options: &HyperfineOptions, ) -> io::Result { + 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, diff --git a/src/hyperfine/types.rs b/src/hyperfine/types.rs index a60b1ad15..bf1998e85 100644 --- a/src/hyperfine/types.rs +++ b/src/hyperfine/types.rs @@ -210,11 +210,14 @@ pub struct HyperfineOptions { /// Which time unit to use for CLI & Markdown output pub time_unit: Option, + + pub names: Option>, } impl Default for HyperfineOptions { fn default() -> HyperfineOptions { HyperfineOptions { + names: None, warmup_count: 0, runs: Runs::default(), min_time_sec: 3.0, diff --git a/src/main.rs b/src/main.rs index f4c0b68ed..d0964fd0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,6 +127,10 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result {} }; + options.names = matches + .values_of("command-name") + .map(|values| values.map(String::from).collect::>()); + options.preparation_command = matches .values_of("prepare") .map(|values| values.map(String::from).collect::>());