diff options
author | David Peter <mail@david-peter.de> | 2022-02-22 13:01:39 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2022-02-22 13:24:05 +0100 |
commit | f19223ba9dd46252d6ea5906618245b7d31500a0 (patch) | |
tree | 5cc8761495d651313848b0603d61d332483c78a7 | |
parent | 7fd4aea49595953f232b4b40abe86e038d8f3e60 (diff) |
Simplify
-rw-r--r-- | src/benchmark/executor.rs | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 357eb26..d271c29 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -40,14 +40,6 @@ pub struct ShellExecutor<'a> { } impl<'a> ShellExecutor<'a> { - fn subtract_shell_spawning_time(&self, time: Second, shell_spawning_time: Second) -> Second { - if time < shell_spawning_time { - 0.0 - } else { - time - shell_spawning_time - } - } - pub fn new(shell: &'a Shell, options: &'a Options) -> Self { ShellExecutor { shell, @@ -77,14 +69,9 @@ impl<'a> Executor for ShellExecutor<'a> { .arg(if cfg!(windows) { "/C" } else { "-c" }) .arg(command.get_command_line()); - let result = execute_and_measure(command_builder) + let mut result = execute_and_measure(command_builder) .with_context(|| format!("Failed to run command '{}'", command.get_command_line()))?; - let mut time_real = result.time_real; - - let mut time_user = result.time_user; - let mut time_system = result.time_system; - if command_failure_action.unwrap_or(self.options.command_failure_action) == CmdFailureAction::RaiseError && !result.status.success() @@ -101,16 +88,16 @@ impl<'a> Executor for ShellExecutor<'a> { // Subtract shell spawning time if let Some(spawning_time) = self.shell_spawning_time { - time_real = self.subtract_shell_spawning_time(time_real, spawning_time.time_real); - time_user = self.subtract_shell_spawning_time(time_user, spawning_time.time_user); - time_system = self.subtract_shell_spawning_time(time_system, spawning_time.time_system); + result.time_real = (result.time_real - spawning_time.time_real).max(0.0); + result.time_user = (result.time_user - spawning_time.time_user).max(0.0); + result.time_system = (result.time_system - spawning_time.time_system).max(0.0); } Ok(( TimingResult { - time_real, - time_user, - time_system, + time_real: result.time_real, + time_user: result.time_user, + time_system: result.time_system, }, result.status, )) |