Rename to run_command_and_measure
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 826449b · Browse files · 2 files·+17 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+17 added−9 removed
- other:+17 added−9 removed
Provenance
- Commit
7c929f7- Tree
63e8d30- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
826449b
2 files changed+17 added−9 removed
modified:src/benchmark/executor.rs+13 added-5 removed
11 unmodified lines12 use anyhow::{bail, Result};13 use statistical::mean;14 15 pub trait Executor {16- fn time_command(16+ /// Run the given command and measure the execution time17+ fn run_command_and_measure(18 &self,19 command: &Command<'_>,20 command_failure_action: Option<CmdFailureAction>,21 ) -> Result<(TimingResult, ExitStatus)>;22 23+ /// Perform a calibration of this executor. For example,24+ /// when running commands through a shell, we need to25+ /// measure the shell spawning time separately in order26+ /// to subtract it from the full runtime later.27 fn calibrate(&mut self) -> Result<()>;28 29+ /// Return the time overhead for this executor when30+ /// performing a measurement. This should return the time31+ /// that is being used in addition to the actual runtime32+ /// of the command.33 fn time_overhead(&self) -> Second;34 }35 36 pub struct ShellExecutor<'a> {20 unmodified lines57 }58 }59 60 impl<'a> Executor for ShellExecutor<'a> {52- /// Run the given shell command and measure the execution time53- fn time_command(61+ fn run_command_and_measure(62 &self,63 command: &Command<'_>,64 command_failure_action: Option<CmdFailureAction>,65 ) -> Result<(TimingResult, ExitStatus)> {58 unmodified lines124 let mut times_system: Vec<Second> = vec![];125 126 for _ in 0..COUNT {127 // Just run the shell without any command120- let res = self.time_command(&Command::new(None, ""), None);128+ let res = self.run_command_and_measure(&Command::new(None, ""), None);129 130 match res {131 Err(_) => {132 let shell_cmd = if cfg!(windows) {57 unmodified lines190 }191 }192 193 impl Executor for MockExecutor {186- fn time_command(194+ fn run_command_and_measure(195 &self,196 command: &Command<'_>,197 _command_failure_action: Option<CmdFailureAction>,198 ) -> Result<(TimingResult, ExitStatus)> {38 unmodified linesmodified:src/benchmark/mod.rs+4 added-4 removed
55 unmodified lines56 command: &Command<'_>,57 error_output: &'static str,58 ) -> Result<TimingResult> {59 self.executor60- .time_command(command, Some(CmdFailureAction::RaiseError))60+ .run_command_and_measure(command, Some(CmdFailureAction::RaiseError))61 .map(|r| r.0)62 .map_err(|_| anyhow!(error_output))63 }64 97 unmodified lines162 };163 164 for _ in 0..self.options.warmup_count {165 let _ = run_preparation_command()?;166- let _ = self.executor.time_command(self.command, None)?;166+ let _ = self.executor.run_command_and_measure(self.command, None)?;167 if let Some(bar) = progress_bar.as_ref() {168 bar.inc(1)169 }170 }17 unmodified lines188 let preparation_overhead =189 preparation_result.map_or(0.0, |res| res.time_real + self.executor.time_overhead());190 191 // Initial timing run192- let (res, status) = self.executor.time_command(self.command, None)?;192+ let (res, status) = self.executor.run_command_and_measure(self.command, None)?;193 let success = status.success();194 195 // Determine number of benchmark runs196 let runs_in_min_time = (self.options.min_benchmarking_time41 unmodified lines238 if let Some(bar) = progress_bar.as_ref() {239 bar.set_message(msg.to_owned())240 }241 242- let (res, status) = self.executor.time_command(self.command, None)?;242+ let (res, status) = self.executor.run_command_and_measure(self.command, None)?;243 let success = status.success();244 245 times_real.push(res.time_real);246 times_user.push(res.time_user);127 unmodified lines