Skip to content
Myr

Detect failure of preparation command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 1fc78cd · Browse files · 1 file+17 added−7 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+17 added−7 removed

  • other:+17 added−7 removed

1 file+17 added−7 removed

modified:src/hyperfine/benchmark.rs+17 added-7 removed
121 unmodified lines
122 time_system: mean(&times_system),123 })124}125126/// Run the command specified by `--prepare`.127fn run_preparation_command(command: &Option<String>) -> io::Result<()> {128 if let &Some(ref preparation_command) = command {129 let res = time_shell_command(preparation_command, CmdFailureAction::RaiseError, None);130 if let Err(_) = res {131 return Err(io::Error::new(132 io::ErrorKind::Other,133 "The preparation command terminated with a non-zero exit code. \134 Append ' || true' to the command if you are sure that this can be ignored.",135 ));136 }137 }138 Ok(())139}140141/// Run the benchmark for a single shell command142pub fn run_benchmark(143 num: usize,144 cmd: &str,
27 unmodified lines
172 // Set up progress bar (and spinner for initial measurement)173 let progress_bar = get_progress_bar(options.min_runs, "Initial time measurement");174175 // Run init / cleanup command161 let run_preparation_command = || {162 if let Some(ref preparation_command) = options.preparation_command {163 let _ = time_shell_command(preparation_command, options.failure_action, None);164 }165 };166 run_preparation_command();176 run_preparation_command(&options.preparation_command)?;177178 // Initial timing run179 let (res, success) =180 time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;
21 unmodified lines
202 progress_bar.set_length(count_remaining);203204 // Gather statistics205 for _ in 0..count_remaining {196 run_preparation_command();206 run_preparation_command(&options.preparation_command)?;207208 let msg = {209 let mean = format_duration(mean(&times_real), None);210 format!("Current estimate: {}", Green.paint(mean))
77 unmodified lines