mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-11-10 03:14:00 +03:00
Implement basic --parameter-list with naive list parsing
This commit is contained in:
parent
538691e999
commit
4a5d08ddc2
@ -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")
|
||||
|
16
src/main.rs
16
src/main.rs
@ -208,6 +208,22 @@ fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {
|
||||
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::<Vec<&str>>();
|
||||
let command_list = command_strings.collect::<Vec<&str>>();
|
||||
|
||||
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user