mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 00:38:56 +00:00
Add multiple --prepare support
Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
This commit is contained in:
1 parent
2c3ced9333
commit
0c0713da30
5 files changed
+36
-12
No files matched your search
@@ -76,10 +76,14 @@ fn build_app() -> App<'static, 'static> {
|
||||
.long("prepare")
|
||||
.short("p")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.number_of_values(1)
|
||||
.value_name("CMD")
|
||||
.help(
|
||||
"Execute CMD before each timing run. This is useful for \
|
||||
clearing disk caches, for example.",
|
||||
"Execute CMD before each timing run. For example, this is \
|
||||
useful for clearing disk caches. This can be mentioned \
|
||||
out multiple time for each command or only one time for \
|
||||
all command.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
|
||||
@@ -234,13 +234,17 @@ pub fn run_benchmark(
|
||||
);
|
||||
|
||||
// Run init command
|
||||
let prepare_cmd = options
|
||||
.preparation_command
|
||||
.as_ref()
|
||||
.map(|preparation_command| match cmd.get_parameter() {
|
||||
Some((param, value)) => Command::new_parametrized(preparation_command, param, value),
|
||||
None => Command::new(preparation_command),
|
||||
});
|
||||
let mut prepare_cmd = None;
|
||||
if let Some(values) = &options.preparation_command {
|
||||
if num >= values.len() {
|
||||
prepare_cmd = Some(new_command_from_get_parameter(
|
||||
cmd,
|
||||
&values[values.len() - 1],
|
||||
));
|
||||
} else {
|
||||
prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[num]));
|
||||
}
|
||||
};
|
||||
let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
|
||||
|
||||
// Initial timing run
|
||||
@@ -404,3 +408,14 @@ pub fn run_benchmark(
|
||||
cmd.get_parameter().map(|p| p.1),
|
||||
))
|
||||
}
|
||||
|
||||
// Get out new Command from a Command and preparation command
|
||||
fn new_command_from_get_parameter<'a>(
|
||||
cmd: &Command<'a>,
|
||||
preparation_command: &'a str,
|
||||
) -> Command<'a> {
|
||||
match cmd.get_parameter() {
|
||||
Some((param, value)) => Command::new_parametrized(preparation_command, param, value),
|
||||
None => Command::new(preparation_command),
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,8 @@ fn get_cpu_times(handle: RawHandle) -> CPUTimes {
|
||||
// Extract times as laid out here: https://support.microsoft.com/en-us/help/188768/info-working-with-the-filetime-structure
|
||||
// Both user_time and kernel_time are spans that the proces spent in either.
|
||||
let user: i64 = (((user_time.dwHighDateTime as i64) << 32)
|
||||
+ user_time.dwLowDateTime as i64) / HUNDRED_NS_PER_MS;
|
||||
+ user_time.dwLowDateTime as i64)
|
||||
/ HUNDRED_NS_PER_MS;
|
||||
let kernel: i64 = (((kernel_time.dwHighDateTime as i64) << 32)
|
||||
+ kernel_time.dwLowDateTime as i64)
|
||||
/ HUNDRED_NS_PER_MS;
|
||||
|
||||
@@ -145,7 +145,7 @@ pub struct HyperfineOptions {
|
||||
pub failure_action: CmdFailureAction,
|
||||
|
||||
/// Command to run before each timing run
|
||||
pub preparation_command: Option<String>,
|
||||
pub preparation_command: Option<Vec<String>>,
|
||||
|
||||
/// Command to run after each benchmark
|
||||
pub cleanup_command: Option<String>,
|
||||
|
||||
+5
-1
@@ -113,7 +113,11 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions,
|
||||
(None, None) => {}
|
||||
};
|
||||
|
||||
options.preparation_command = matches.value_of("prepare").map(String::from);
|
||||
if let Some(values) = matches.values_of("prepare") {
|
||||
options.preparation_command = Some(values.map(String::from).collect::<Vec<String>>());
|
||||
} else {
|
||||
options.preparation_command = None;
|
||||
}
|
||||
|
||||
options.cleanup_command = matches.value_of("cleanup").map(String::from);
|
||||
|
||||
|
||||
Reference in new issue
Block a user