Further simplifications
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 1eafcf4 · Browse files · 2 files·+35 added−30 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+35 added−30 removed
- other:+35 added−30 removed
Provenance
- Commit
3558138- Tree
da7792e- Author
David Peter <mail@david-peter.de>- Committer
David Peter <mail@david-peter.de>- Parent
1eafcf4
2 files changed+35 added−30 removed
modified:src/benchmark/executor.rs+7 added-6 removed
13 unmodified lines14 use super::measurement::{Measurement, Measurements};15 16 use anyhow::{bail, Context, Result};17 18+#[derive(Clone, Copy)]19 pub enum BenchmarkIteration {20 NonBenchmarkRun,21 Warmup(u64),22 Benchmark(u64),13 unmodified lines36 /// Run the given command and measure the execution time37 fn run_command_and_measure(38 &self,39 command: &Command<'_>,39- iteration: &BenchmarkIteration,40+ iteration: BenchmarkIteration,41 command_failure_action: Option<CmdFailureAction>,42 output_policy: &CommandOutputPolicy,43 ) -> Result<Measurement>;44 11 unmodified lines56 }57 58 fn run_command_and_measure_common(59 mut command: std::process::Command,59- iteration: &BenchmarkIteration,60+ iteration: BenchmarkIteration,61 command_failure_action: CmdFailureAction,62 command_input_policy: &CommandInputPolicy,63 command_output_policy: &CommandOutputPolicy,64 command_name: &str,67 unmodified lines132 impl Executor for RawExecutor<'_> {133 fn run_command_and_measure(134 &self,135 command: &Command<'_>,135- iteration: &BenchmarkIteration,136+ iteration: BenchmarkIteration,137 command_failure_action: Option<CmdFailureAction>,138 output_policy: &CommandOutputPolicy,139 ) -> Result<Measurement> {140 run_command_and_measure_common(34 unmodified lines175 impl Executor for ShellExecutor<'_> {176 fn run_command_and_measure(177 &self,178 command: &Command<'_>,178- iteration: &BenchmarkIteration,179+ iteration: BenchmarkIteration,180 command_failure_action: Option<CmdFailureAction>,181 output_policy: &CommandOutputPolicy,182 ) -> Result<Measurement> {183 let on_windows_cmd = cfg!(windows) && *self.shell == Shell::Default("cmd.exe");46 unmodified lines230 for _ in 0..COUNT {231 // Just run the shell without any command232 let res = self.run_command_and_measure(233 &Command::new(None, ""),233- &BenchmarkIteration::NonBenchmarkRun,234+ BenchmarkIteration::NonBenchmarkRun,235 None,236 &CommandOutputPolicy::Null,237 );238 65 unmodified lines304 impl Executor for MockExecutor {305 fn run_command_and_measure(306 &self,307 command: &Command<'_>,307- _iteration: &BenchmarkIteration,308+ _iteration: BenchmarkIteration,309 _command_failure_action: Option<CmdFailureAction>,310 _output_policy: &CommandOutputPolicy,311 ) -> Result<Measurement> {312 #[cfg(unix)]39 unmodified linesmodified:src/benchmark/mod.rs+28 added-24 removed
56 unmodified lines57 &self,58 command: &Command<'_>,59 error_output: &'static str,60 output_policy: &CommandOutputPolicy,61- iteration: &executor::BenchmarkIteration,61+ iteration: executor::BenchmarkIteration,62 ) -> Result<Measurement> {63 self.executor64 .run_command_and_measure(65 command,8 unmodified lines74 fn run_setup_command(75 &self,76 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,77 output_policy: &CommandOutputPolicy,78- iteration: executor::BenchmarkIteration,78 ) -> Result<Measurement> {79 let command = self80 .options81 .setup_command3 unmodified lines85 let error_output = "The setup command terminated with a non-zero exit code. \86 Append ' || true' to the command if you are sure that this can be ignored.";87 88 Ok(command90- .map(|cmd| self.run_intermediate_command(&cmd, error_output, output_policy, &iteration))89+ .map(|cmd| {90+ self.run_intermediate_command(91+ &cmd,92+ error_output,93+ output_policy,94+ BenchmarkIteration::NonBenchmarkRun,95+ )96+ })97 .transpose()?98 .unwrap_or_default())99 }100 1 unmodified line102 fn run_cleanup_command(103 &self,104 parameters: impl IntoIterator<Item = ParameterNameAndValue<'a>>,105 output_policy: &CommandOutputPolicy,100- iteration: executor::BenchmarkIteration,106 ) -> Result<Measurement> {107 let command = self108 .options109 .cleanup_command3 unmodified lines113 let error_output = "The cleanup command terminated with a non-zero exit code. \114 Append ' || true' to the command if you are sure that this can be ignored.";115 116 Ok(command112- .map(|cmd| self.run_intermediate_command(&cmd, error_output, output_policy, &iteration))117+ .map(|cmd| {118+ self.run_intermediate_command(119+ &cmd,120+ error_output,121+ output_policy,122+ BenchmarkIteration::NonBenchmarkRun,123+ )124+ })125 .transpose()?126 .unwrap_or_default())127 }128 1 unmodified line130 fn run_preparation_command(131 &self,132 command: &Command<'_>,133 output_policy: &CommandOutputPolicy,122- iteration: &executor::BenchmarkIteration,134+ iteration: executor::BenchmarkIteration,135 ) -> Result<Measurement> {136 let error_output = "The preparation command terminated with a non-zero exit code. \137 Append ' || true' to the command if you are sure that this can be ignored.";138 9 unmodified lines148 ) -> Result<Measurement> {149 let error_output = "The conclusion command terminated with a non-zero exit code. \150 Append ' || true' to the command if you are sure that this can be ignored.";151 140- self.run_intermediate_command(command, error_output, output_policy, &iteration)152+ self.run_intermediate_command(command, error_output, output_policy, iteration)153 }154 155 /// Run the benchmark for a single command156 pub fn run(&self) -> Result<BenchmarkResult> {24 unmodified lines181 self.command.get_parameters().iter().cloned(),182 )183 });184 173- let run_preparation_command = |iteration: &executor::BenchmarkIteration| {185+ let run_preparation_command = |iteration: executor::BenchmarkIteration| {186 preparation_command187 .as_ref()188 .map(|cmd| self.run_preparation_command(cmd, output_policy, iteration))189 .transpose()17 unmodified lines207 .map(|cmd| self.run_conclusion_command(cmd, output_policy, iteration))208 .transpose()209 };210 199- self.run_setup_command(200- self.command.get_parameters().iter().cloned(),201- output_policy,202- executor::BenchmarkIteration::NonBenchmarkRun,203- )?;211+ self.run_setup_command(self.command.get_parameters().iter().cloned(), output_policy)?;212 213 // Warmup phase214 if self.options.warmup_count > 0 {215 let progress_bar = if self.options.output_style != OutputStyleOption::Disabled {7 unmodified lines223 };224 225 for i in 0..self.options.warmup_count {226 let warmup_iteration = BenchmarkIteration::Warmup(i);219- let _ = run_preparation_command(&warmup_iteration)?;227+ let _ = run_preparation_command(warmup_iteration)?;228 let _ = self.executor.run_command_and_measure(229 self.command,222- &warmup_iteration,230+ warmup_iteration,231 None,232 output_policy,233 )?;234 let _ = run_conclusion_command(warmup_iteration)?;17 unmodified lines252 None253 };254 255 let benchmark_iteration = BenchmarkIteration::Benchmark(0);248- let preparation_result = run_preparation_command(&benchmark_iteration)?;256+ let preparation_result = run_preparation_command(benchmark_iteration)?;257 let preparation_overhead = preparation_result.map_or(Time::zero(), |res| {258 res.time_wall_clock + self.executor.time_overhead()259 });260 261 // Initial timing run262 let res = self.executor.run_command_and_measure(263 self.command,256- &benchmark_iteration,264+ benchmark_iteration,265 None,266 output_policy,267 )?;268 let success = res.exit_status.success();39 unmodified lines308 309 // Gather statistics (perform the actual benchmark)310 for i in 0..count_remaining {311 let benchmark_iteration = BenchmarkIteration::Benchmark(i + 1);304- run_preparation_command(&benchmark_iteration)?;312+ run_preparation_command(benchmark_iteration)?;313 314 let msg = {315 let t_wall_clock_mean = measurements.time_wall_clock_mean();316 let time_unit = self9 unmodified lines326 }327 328 let res = self.executor.run_command_and_measure(329 self.command,322- &benchmark_iteration,330+ benchmark_iteration,331 None,332 output_policy,333 )?;334 let success = res.exit_status.success();124 unmodified lines459 if self.options.output_style != OutputStyleOption::Disabled {460 console_writeln!(io::stdout(), " ")?;461 }462 455- self.run_cleanup_command(456- self.command.get_parameters().iter().cloned(),457- output_policy,458- executor::BenchmarkIteration::NonBenchmarkRun,459- )?;463+ self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;464 465 Ok(BenchmarkResult {466 command: self.command.get_name(),467 command_with_unused_parameters: self.command.get_name_with_unused_parameters(),34 unmodified lines