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
Provenance
- Commit
a08ab7c- Tree
74eac31- Author
rleungx <rleungx@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
cad3d0c
1 file changed+15 added−12 removed
modified:src/hyperfine/benchmark.rs+15 added-12 removed
12 unmodified lines13 use hyperfine::shell::execute_and_time;14 15 16 /// Results from timing a single shell command17-#[derive(Debug, Copy, Clone)]17+#[derive(Debug, Default, Copy, Clone)]18 pub struct TimingResult {19 /// Wall clock time20 pub time_real: Second,21 91 unmodified lines113 })114 }115 116 /// Run the command specified by `--prepare`.117-fn run_preparation_command(command: &Option<String>) -> io::Result<()> {117+fn 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 line123 "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 }133 134 /// Run the benchmark for a single shell command135 pub fn run_benchmark(37 unmodified lines173 &options.output_style,174 );175 176 // Run init / cleanup command174- run_preparation_command(&options.preparation_command)?;177+ let prepare_res = run_preparation_command(&options.preparation_command)?;178 179 // Initial timing run180 let (res, success) =181 time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;182 183 // 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;186 187 let count = if runs_in_min_time >= options.min_runs {188 runs_in_min_time189 } else {2 unmodified lines192 193 let count_remaining = count - 1;194 195 // 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);199 200 all_succeeded = all_succeeded && success;201 202 // Re-configure the progress bar203 progress_bar.set_length(count_remaining);204 205 // Gather statistics206 for _ in 0..count_remaining {204- run_preparation_command(&options.preparation_command)?;207+ let prepare_res = run_preparation_command(&options.preparation_command)?;208 209 let msg = {210 let mean = format_duration(mean(×_real), None);211 format!("Current estimate: {}", mean.to_string().green())2 unmodified lines214 215 let (res, success) =216 time_shell_command(cmd, options.failure_action, Some(shell_spawning_time))?;217 215- 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);221 222 all_succeeded = all_succeeded && success;223 224 progress_bar.inc(1);73 unmodified lines