Skip to content
Myr

Add multiple --prepare support

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 2c3ced9 · Browse files · 5 files+36 added−12 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

5 files+36 added−12 removed

  • other:+36 added−12 removed

5 files+36 added−12 removed

modified:src/hyperfine/timer/windows_timer.rs+2 added-1 removed
63 unmodified lines
64 if res != 0 {65 // Extract times as laid out here: https://support.microsoft.com/en-us/help/188768/info-working-with-the-filetime-structure66 // Both user_time and kernel_time are spans that the proces spent in either.67 let user: i64 = (((user_time.dwHighDateTime as i64) << 32)68 + user_time.dwLowDateTime as i64) / HUNDRED_NS_PER_MS;68 + user_time.dwLowDateTime as i64)69 / HUNDRED_NS_PER_MS;70 let kernel: i64 = (((kernel_time.dwHighDateTime as i64) << 32)71 + kernel_time.dwLowDateTime as i64)72 / HUNDRED_NS_PER_MS;73 (user, kernel)
10 unmodified lines
modified:src/hyperfine/app.rs+6 added-2 removed
74 unmodified lines
75 Arg::with_name("prepare")76 .long("prepare")77 .short("p")78 .takes_value(true)79 .multiple(true)80 .number_of_values(1)81 .value_name("CMD")82 .help(81 "Execute CMD before each timing run. This is useful for \82 clearing disk caches, for example.",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.",87 ),88 )89 .arg(90 Arg::with_name("cleanup")
116 unmodified lines
modified:src/hyperfine/benchmark.rs+22 added-7 removed
232 unmodified lines
233 options.output_style,234 );235236 // Run init command237 let prepare_cmd = options238 .preparation_command239 .as_ref()240 .map(|preparation_command| match cmd.get_parameter() {241 Some((param, value)) => Command::new_parametrized(preparation_command, param, value),242 None => Command::new(preparation_command),243 });237 let mut prepare_cmd = None;238 if let Some(values) = &options.preparation_command {239 if num >= values.len() {240 prepare_cmd = Some(new_command_from_get_parameter(241 cmd,242 &values[values.len() - 1],243 ));244 } else {245 prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[num]));246 }247 };248 let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;249250 // Initial timing run251 let (res, success) = time_shell_command(
155 unmodified lines
407 times_real,408 cmd.get_parameter().map(|p| p.1),409 ))410}411412// Get out new Command from a Command and preparation command413fn new_command_from_get_parameter<'a>(414 cmd: &Command<'a>,415 preparation_command: &'a str,416) -> Command<'a> {417 match cmd.get_parameter() {418 Some((param, value)) => Command::new_parametrized(preparation_command, param, value),419 None => Command::new(preparation_command),420 }421}
modified:src/hyperfine/types.rs+1 added-1 removed
143 unmodified lines
144 /// Whether or not to ignore non-zero exit codes145 pub failure_action: CmdFailureAction,146147 /// Command to run before each timing run148 pub preparation_command: Option<String>,148 pub preparation_command: Option<Vec<String>>,149150 /// Command to run after each benchmark151 pub cleanup_command: Option<String>,152
94 unmodified lines
modified:src/main.rs+5 added-1 removed
111 unmodified lines
112 }113 (None, None) => {}114 };115116 options.preparation_command = matches.value_of("prepare").map(String::from);116 if let Some(values) = matches.values_of("prepare") {117 options.preparation_command = Some(values.map(String::from).collect::<Vec<String>>());118 } else {119 options.preparation_command = None;120 }121122 options.cleanup_command = matches.value_of("cleanup").map(String::from);123124 options.show_output = matches.is_present("show-output");
77 unmodified lines