From 7c929f7e48167c2561ec464c39171aa033fa8e3c Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 22 Feb 2022 10:59:33 +0100 Subject: [PATCH] Rename to run_command_and_measure --- src/benchmark/executor.rs | 18 +++++++++++++----- src/benchmark/mod.rs | 8 ++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index 0c9e8ee..74a9d7d 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -13,14 +13,23 @@ use anyhow::{bail, Result}; use statistical::mean; pub trait Executor { - fn time_command( + /// Run the given command and measure the execution time + fn run_command_and_measure( &self, command: &Command<'_>, command_failure_action: Option, ) -> Result<(TimingResult, ExitStatus)>; + /// Perform a calibration of this executor. For example, + /// when running commands through a shell, we need to + /// measure the shell spawning time separately in order + /// to subtract it from the full runtime later. fn calibrate(&mut self) -> Result<()>; + /// Return the time overhead for this executor when + /// performing a measurement. This should return the time + /// that is being used in addition to the actual runtime + /// of the command. fn time_overhead(&self) -> Second; } @@ -49,8 +58,7 @@ impl<'a> ShellExecutor<'a> { } impl<'a> Executor for ShellExecutor<'a> { - /// Run the given shell command and measure the execution time - fn time_command( + fn run_command_and_measure( &self, command: &Command<'_>, command_failure_action: Option, @@ -117,7 +125,7 @@ impl<'a> Executor for ShellExecutor<'a> { for _ in 0..COUNT { // Just run the shell without any command - let res = self.time_command(&Command::new(None, ""), None); + let res = self.run_command_and_measure(&Command::new(None, ""), None); match res { Err(_) => { @@ -183,7 +191,7 @@ impl MockExecutor { } impl Executor for MockExecutor { - fn time_command( + fn run_command_and_measure( &self, command: &Command<'_>, _command_failure_action: Option, diff --git a/src/benchmark/mod.rs b/src/benchmark/mod.rs index d26dc39..410e1c3 100644 --- a/src/benchmark/mod.rs +++ b/src/benchmark/mod.rs @@ -57,7 +57,7 @@ impl<'a> Benchmark<'a> { error_output: &'static str, ) -> Result { self.executor - .time_command(command, Some(CmdFailureAction::RaiseError)) + .run_command_and_measure(command, Some(CmdFailureAction::RaiseError)) .map(|r| r.0) .map_err(|_| anyhow!(error_output)) } @@ -163,7 +163,7 @@ impl<'a> Benchmark<'a> { for _ in 0..self.options.warmup_count { let _ = run_preparation_command()?; - let _ = self.executor.time_command(self.command, None)?; + let _ = self.executor.run_command_and_measure(self.command, None)?; if let Some(bar) = progress_bar.as_ref() { bar.inc(1) } @@ -189,7 +189,7 @@ impl<'a> Benchmark<'a> { preparation_result.map_or(0.0, |res| res.time_real + self.executor.time_overhead()); // Initial timing run - let (res, status) = self.executor.time_command(self.command, None)?; + let (res, status) = self.executor.run_command_and_measure(self.command, None)?; let success = status.success(); // Determine number of benchmark runs @@ -239,7 +239,7 @@ impl<'a> Benchmark<'a> { bar.set_message(msg.to_owned()) } - let (res, status) = self.executor.time_command(self.command, None)?; + let (res, status) = self.executor.run_command_and_measure(self.command, None)?; let success = status.success(); times_real.push(res.time_real);