From 4a5d08ddc2a42918bfd8e5ff58e0eb9aa1320eea Mon Sep 17 00:00:00 2001 From: Hasan Ibraheem Date: Thu, 17 Oct 2019 12:27:32 -0400 Subject: [PATCH] Implement basic --parameter-list with naive list parsing --- src/hyperfine/app.rs | 15 +++++++++++++++ src/main.rs | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/hyperfine/app.rs b/src/hyperfine/app.rs index 471f7e2..7a09dfd 100644 --- a/src/hyperfine/app.rs +++ b/src/hyperfine/app.rs @@ -129,6 +129,21 @@ fn build_app() -> App<'static, 'static> { This performs benchmarks for 'sleep 0.3', 'sleep 0.5' and 'sleep 0.7'.", ), ) + .arg( + Arg::with_name("parameter-list") + .long("parameter-list") + .short("L") + .takes_value(true) + .allow_hyphen_values(true) + .value_names(&["VAR", "VALUES"]) + .conflicts_with("parameter-scan") + .help( + "Perform benchmark runs for each value in the comma-seperated list VALUES. \ + Replaces the string '{VAR}' in each command by the current parameter value\ + .\n\nExample: hyperfine -L threads 1,2,4 'make -j {threads}'\n\n\ + This performs benchmarks for 'make -j 1', 'make -j 2', and 'make -j 4'.", + ), + ) .arg( Arg::with_name("style") .long("style") diff --git a/src/main.rs b/src/main.rs index 18b8da7..95c4220 100644 --- a/src/main.rs +++ b/src/main.rs @@ -208,6 +208,22 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { Ok(commands) => commands, Err(e) => error(e.description()), } + } else if let Some(mut args) = matches.values_of("parameter-list") { + let param_name = args.next().unwrap(); + let param_list_str = args.next().unwrap(); + + let param_list = param_list_str.split(',').collect::>(); + let command_list = command_strings.collect::>(); + + let mut commands = Vec::with_capacity(param_list.len() * command_list.len()); + + for value in param_list { + for cmd in &command_list { + commands.push(Command::new_parametrized(cmd, param_name, value.to_string())); + } + } + + commands } else { command_strings.map(Command::new).collect() }