Restructure run_intermediate_command
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 f4ef945 · Browse files · 1 file·+32 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+32 added−24 removed
- other:+32 added−24 removed
Provenance
- Commit
662d5ca- Tree
442c7c6- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
f4ef945
1 file changed+32 added−24 removed
modified:src/benchmark/scheduler.rs+32 added-24 removed
236 unmodified lines237 }238 239 fn run_intermediate_command(240 &self,241- command: &Option<Command<'_>>,241+ command: &Command<'_>,242 error_output: &'static str,243 ) -> Result<TimingResult> {244- if let Some(ref cmd) = command {245- let res = time_shell_command(246- &self.options.shell,247- cmd,248- self.options.command_output_policy,249- CmdFailureAction::RaiseError,250- None,251- );252- if res.is_err() {253- bail!(error_output);244+ let res = time_shell_command(245+ &self.options.shell,246+ command,247+ self.options.command_output_policy,248+ CmdFailureAction::RaiseError,249+ None,250+ );251+ if res.is_err() {252+ bail!(error_output);254- }255- return res.map(|r| r.0);253 }257- Ok(TimingResult {258- ..Default::default()259- })254+ return res.map(|r| r.0);255 }256 257 /// Run the command specified by `--setup`.258 fn run_setup_command(8 unmodified lines267 268 let error_output = "The setup command terminated with a non-zero exit code. \269 Append ' || true' to the command if you are sure that this can be ignored.";270 276- self.run_intermediate_command(&command, error_output)271+ Ok(command272+ .map(|cmd| self.run_intermediate_command(&cmd, error_output))273+ .transpose()?274+ .unwrap_or_default())275 }276 277 /// Run the command specified by `--cleanup`.278 fn run_cleanup_command(8 unmodified lines287 288 let error_output = "The cleanup command terminated with a non-zero exit code. \289 Append ' || true' to the command if you are sure that this can be ignored.";290 293- self.run_intermediate_command(&command, error_output)291+ Ok(command292+ .map(|cmd| self.run_intermediate_command(&cmd, error_output))293+ .transpose()?294+ .unwrap_or_default())295 }296 297 /// Run the command specified by `--prepare`.297- fn run_preparation_command(&self, command: &Option<Command<'_>>) -> Result<TimingResult> {298+ fn run_preparation_command(&self, command: &Command<'_>) -> Result<TimingResult> {299 let error_output = "The preparation command terminated with a non-zero exit code. \300 Append ' || true' to the command if you are sure that this can be ignored.";301 302 self.run_intermediate_command(command, error_output)21 unmodified lines324 let mut times_system: Vec<Second> = vec![];325 let mut exit_codes: Vec<Option<i32>> = vec![];326 let mut all_succeeded = true;327 327- let prepare_cmd = self.options.preparation_command.as_ref().map(|values| {328+ let preparation_command = self.options.preparation_command.as_ref().map(|values| {329 let preparation_command = if values.len() == 1 {330 &values[0]331 } else {332 &values[benchmark_number]3 unmodified lines336 preparation_command,337 command.get_parameters().iter().cloned(),338 )339 });340+ let run_preparation_command = || {341+ if let Some(ref cmd) = preparation_command {342+ self.run_preparation_command(cmd)343+ } else {344+ Ok(TimingResult::default())345+ }346+ };347 348 self.run_setup_command(command.get_parameters().iter().cloned())?;349 350 // Warmup phase8 unmodified lines359 None360 };361 362 for _ in 0..self.options.warmup_count {355- let _ = self.run_preparation_command(&prepare_cmd)?;363+ let _ = run_preparation_command()?;364 let _ = time_shell_command(365 &self.options.shell,366 command,367 self.options.command_output_policy,19 unmodified lines387 } else {388 None389 };390 383- let prepare_result = self.run_preparation_command(&prepare_cmd)?;391+ let preparation_result = run_preparation_command()?;392 393 // Initial timing run394 let (res, status) = time_shell_command(395 &self.options.shell,5 unmodified lines401 let success = status.success();402 403 // Determine number of benchmark runs404 let runs_in_min_time = (self.options.min_benchmarking_time397- / (res.time_real + prepare_result.time_real + shell_spawning_time.time_real))405+ / (res.time_real + preparation_result.time_real + shell_spawning_time.time_real))406 as u64;407 408 let count = {409 let min = cmp::max(runs_in_min_time, self.options.run_bounds.min);25 unmodified lines435 }436 437 // Gather statistics (perform the actual benchmark)438 for _ in 0..count_remaining {431- self.run_preparation_command(&prepare_cmd)?;439+ run_preparation_command()?;440 441 let msg = {442 let mean = format_duration(mean(×_real), self.options.time_unit);443 format!("Current estimate: {}", mean.to_string().green())143 unmodified lines