refactor code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Saurav Sharma · committed by David Peter · parent bc82bd5 · Browse files · 3 files·+20 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
Diff stats
3 files+20 added−27 removed
- other:+20 added−27 removed
Provenance
- Commit
d1cd30b- Tree
60a12a6- Author
Saurav Sharma <appdroiddeveloper@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
bc82bd5
3 files changed+20 added−27 removed
modified:src/hyperfine/app.rs+5 added-4 removed
78 unmodified lines79 .multiple(true)80 .number_of_values(1)81 .value_name("CMD")82 .help(83- "Execute CMD before each timing run. For example, this is \84- useful for clearing disk caches. This can be mentioned \85- out multiple time for each command or only one time for \86- all command.",83+ "Execute CMD before each timing run. This is useful for \84+ clearing disk caches, for example. \nThe --prepare option can \85+ be specified once for all commands or multiple times, once for \86+ each command. In the latter case, each preparation command will \87+ be run prior to the corresponding benchmark command.",88 ),89 )90 .arg(91 Arg::with_name("cleanup")116 unmodified linesmodified:src/hyperfine/benchmark.rs+12 added-18 removed
232 unmodified lines233 options.output_style,234 );235 236 // Run init command237- let mut prepare_cmd = None;238- if let Some(values) = &options.preparation_command {239- if values.len() == 1 {240- prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[0]));241- } else {242- prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[num]));237+ let prepare_cmd = options.preparation_command.as_ref().map(|values| {238+ let corresponding_prepare_cmd = match values.len() {239+ 1 => &values[0],240+ _ => &values[num],241+ };242+ match cmd.get_parameter() {243+ Some((param, value)) => {244+ Command::new_parametrized(corresponding_prepare_cmd, param, value)245+ }246+ None => Command::new(corresponding_prepare_cmd),247 }244- };248+ });249+250 let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;251 252 // Initial timing run253 let (res, success) = time_shell_command(155 unmodified lines409 times_real,410 cmd.get_parameter().map(|p| p.1),411 ))412 }408-409-// Get out new Command from a Command and preparation command410-fn new_command_from_get_parameter<'a>(411- cmd: &Command<'a>,412- preparation_command: &'a str,413-) -> Command<'a> {414- match cmd.get_parameter() {415- Some((param, value)) => Command::new_parametrized(preparation_command, param, value),416- None => Command::new(preparation_command),417- }418-}modified:src/main.rs+3 added-5 removed
121 unmodified lines122 }123 (None, None) => {}124 };125 126- if let Some(values) = matches.values_of("prepare") {127- options.preparation_command = Some(values.map(String::from).collect::<Vec<String>>());128- } else {129- options.preparation_command = None;130- }126+ options.preparation_command = matches127+ .values_of("prepare")128+ .map(|values| values.map(String::from).collect::<Vec<String>>());129 130 options.cleanup_command = matches.value_of("cleanup").map(String::from);131 132 options.show_output = matches.is_present("show-output");77 unmodified lines