Skip to content
Myr

correctly estimate full execution time

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

authored by rleungx · committed by David Peter · parent cad3d0c · Browse files · 1 file+15 added−12 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+15 added−12 removed

  • other:+15 added−12 removed

1 file+15 added−12 removed

modified:src/hyperfine/benchmark.rs+15 added-12 removed
12 unmodified lines
13use hyperfine::shell::execute_and_time;141516/// Results from timing a single shell command17#[derive(Debug, Copy, Clone)]17#[derive(Debug, Default, Copy, Clone)]18pub struct TimingResult {19 /// Wall clock time20 pub time_real: Second,21
91 unmodified lines
113 })114}115116/// Run the command specified by `--prepare`.117fn run_preparation_command(command: &Option<String>) -> io::Result<()> {117fn run_preparation_command(command: &Option<String>) -> io::Result<TimingResult> {118 if let &Some(ref preparation_command) = command {119 let res = time_shell_command(preparation_command, CmdFailureAction::RaiseError, None);120 if res.is_err() {121 return Err(io::Error::new(
1 unmodified line
123 "The preparation command terminated with a non-zero exit code. \124 Append ' || true' to the command if you are sure that this can be ignored.",125 ));126 }127 return res.map(|r| r.0);128 }128 Ok(())129 Ok(TimingResult {130 ..Default::default()131 })132}133134/// Run the benchmark for a single shell command135pub fn run_benchmark(
37 unmodified lines
173 &options.output_style,174 );175176 // Run init / cleanup command174 run_preparation_command(&options.preparation_command)?;177 let prepare_res = run_preparation_command(&options.preparation_command)?;178179 // Initial timing run180 let (res, success) =181 time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;182183 // Determine number of benchmark runs184 let runs_in_min_time =182 (options.min_time_sec / (res.time_real + shell_spawning_time.time_real)) as u64;185 (options.min_time_sec / (res.time_real + prepare_res.time_real + shell_spawning_time.time_real)) as u64;186187 let count = if runs_in_min_time >= options.min_runs {188 runs_in_min_time189 } else {
2 unmodified lines
192193 let count_remaining = count - 1;194195 // Save the first result193 times_real.push(res.time_real);194 times_user.push(res.time_user);195 times_system.push(res.time_system);196 times_real.push(res.time_real + prepare_res.time_real);197 times_user.push(res.time_user + prepare_res.time_user);198 times_system.push(res.time_system + prepare_res.time_system);199200 all_succeeded = all_succeeded && success;201202 // Re-configure the progress bar203 progress_bar.set_length(count_remaining);204205 // Gather statistics206 for _ in 0..count_remaining {204 run_preparation_command(&options.preparation_command)?;207 let prepare_res = run_preparation_command(&options.preparation_command)?;208209 let msg = {210 let mean = format_duration(mean(&times_real), None);211 format!("Current estimate: {}", mean.to_string().green())
2 unmodified lines
214215 let (res, success) =216 time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;217215 times_real.push(res.time_real);216 times_user.push(res.time_user);217 times_system.push(res.time_system);218 times_real.push(res.time_real + prepare_res.time_real);219 times_user.push(res.time_user + prepare_res.time_user);220 times_system.push(res.time_system + prepare_res.time_system);221222 all_succeeded = all_succeeded && success;223224 progress_bar.inc(1);
73 unmodified lines