refactor code

Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
This commit is contained in:
Saurav Sharma authored and David Peter committed 2019-10-13 15:11:39 +02:00
1 parent bc82bd5f23
commit d1cd30b2a3
3 files changed
+20 -27

No files matched your search

+5 -4
View File
@@ -80,10 +80,11 @@ fn build_app() -> App<'static, 'static> {
.number_of_values(1)
.value_name("CMD")
.help(
"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.",
"Execute CMD before each timing run. This is useful for \
clearing disk caches, for example. \nThe --prepare option can \
be specified once for all commands or multiple times, once for \
each command. In the latter case, each preparation command will \
be run prior to the corresponding benchmark command.",
),
)
.arg(
+12 -18
View File
@@ -234,14 +234,19 @@ pub fn run_benchmark(
);
// Run init command
let mut prepare_cmd = None;
if let Some(values) = &options.preparation_command {
if values.len() == 1 {
prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[0]));
} else {
prepare_cmd = Some(new_command_from_get_parameter(cmd, &values[num]));
let prepare_cmd = options.preparation_command.as_ref().map(|values| {
let corresponding_prepare_cmd = match values.len() {
1 => &values[0],
_ => &values[num],
};
match cmd.get_parameter() {
Some((param, value)) => {
Command::new_parametrized(corresponding_prepare_cmd, param, value)
}
None => Command::new(corresponding_prepare_cmd),
}
};
});
let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
// Initial timing run
@@ -405,14 +410,3 @@ 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),
}
}
+3 -5
View File
@@ -123,11 +123,9 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions,
(None, None) => {}
};
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.preparation_command = matches
.values_of("prepare")
.map(|values| values.map(String::from).collect::<Vec<String>>());
options.cleanup_command = matches.value_of("cleanup").map(String::from);