Skip to content
Myr

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

2 files+17 added−9 removed

modified:src/benchmark/executor.rs+13 added-5 removed
11 unmodified lines
12use anyhow::{bail, Result};13use statistical::mean;1415pub 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)>;2223 /// 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<()>;2829 /// 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}3536pub struct ShellExecutor<'a> {
20 unmodified lines
57 }58}5960impl<'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 lines
124 let mut times_system: Vec<Second> = vec![];125126 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);129130 match res {131 Err(_) => {132 let shell_cmd = if cfg!(windows) {
57 unmodified lines
190 }191}192193impl 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 lines
modified:src/benchmark/mod.rs+4 added-4 removed
55 unmodified lines
56 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 lines
162 };163164 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 lines
188 let preparation_overhead =189 preparation_result.map_or(0.0, |res| res.time_real + self.executor.time_overhead());190191 // 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();194195 // Determine number of benchmark runs196 let runs_in_min_time = (self.options.min_benchmarking_time
41 unmodified lines
238 if let Some(bar) = progress_bar.as_ref() {239 bar.set_message(msg.to_owned())240 }241242 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();244245 times_real.push(res.time_real);246 times_user.push(res.time_user);
127 unmodified lines