mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Support parameter in preparation command
This commit is contained in:
1 parent
4d68c5f72c
commit
fb9b30c7f8
2 files changed
+16
-10
No files matched your search
+12
-10
@@ -131,16 +131,11 @@ pub fn mean_shell_spawning_time(
|
|||||||
|
|
||||||
/// Run the command specified by `--prepare`.
|
/// Run the command specified by `--prepare`.
|
||||||
fn run_preparation_command(
|
fn run_preparation_command(
|
||||||
command: &Option<String>,
|
command: &Option<Command>,
|
||||||
show_output: bool,
|
show_output: bool,
|
||||||
) -> io::Result<TimingResult> {
|
) -> io::Result<TimingResult> {
|
||||||
if let &Some(ref preparation_command) = command {
|
if let Some(ref cmd) = command {
|
||||||
let res = time_shell_command(
|
let res = time_shell_command(cmd, show_output, CmdFailureAction::RaiseError, None);
|
||||||
&Command::new(preparation_command),
|
|
||||||
show_output,
|
|
||||||
CmdFailureAction::RaiseError,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
@@ -198,7 +193,14 @@ pub fn run_benchmark(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Run init / cleanup command
|
// Run init / cleanup command
|
||||||
let prepare_res = run_preparation_command(&options.preparation_command, options.show_output)?;
|
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 prepare_res = run_preparation_command(&prepare_cmd, options.show_output)?;
|
||||||
|
|
||||||
// Initial timing run
|
// Initial timing run
|
||||||
let (res, success) = time_shell_command(
|
let (res, success) = time_shell_command(
|
||||||
@@ -233,7 +235,7 @@ pub fn run_benchmark(
|
|||||||
|
|
||||||
// Gather statistics
|
// Gather statistics
|
||||||
for _ in 0..count_remaining {
|
for _ in 0..count_remaining {
|
||||||
run_preparation_command(&options.preparation_command, options.show_output)?;
|
run_preparation_command(&prepare_cmd, options.show_output)?;
|
||||||
|
|
||||||
let msg = {
|
let msg = {
|
||||||
let mean = format_duration(mean(×_real), None);
|
let mean = format_duration(mean(×_real), None);
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ impl<'a> Command<'a> {
|
|||||||
None => self.expression.into(),
|
None => self.expression.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_parameter(&self) -> Option<(&'a str, i32)> {
|
||||||
|
self.parameter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> fmt::Display for Command<'a> {
|
impl<'a> fmt::Display for Command<'a> {
|
||||||
|
|||||||
Reference in new issue
Block a user