updates as requested in the review
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by knidarkness · committed by David Peter · parent 5bc9441 · Browse files · 3 files·+61 added−35 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+61 added−35 removed
- other:+61 added−35 removed
Provenance
- Commit
34eb150- Tree
53993c7- Author
knidarkness <knidarkness@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
5bc9441
3 files changed+61 added−35 removed
modified:src/hyperfine/benchmark.rs+52 added-30 removed
3 unmodified lines4 5 use colored::*;6 use statistical::{mean, median, standard_deviation};7 8-use indicatif::{ProgressBar};9-8 use crate::hyperfine::format::{format_duration, format_duration_unit};9 use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};10 use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11 use crate::hyperfine::shell::execute_and_time;81 unmodified lines93 style: OutputStyleOption,94 show_output: bool,95 ) -> io::Result<TimingResult> {96 const COUNT: u64 = 200;99- let mut progress_bar: Option<ProgressBar> = None;100- if style != OutputStyleOption::None { 101- progress_bar = Some(get_progress_bar(COUNT, "Measuring shell spawning time", style)); 102- }97+ let progress_bar = if style != OutputStyleOption::Disabled {98+ Some(get_progress_bar(99+ COUNT,100+ "Measuring shell spawning time",101+ style,102+ ))103+ } else {104+ None105+ };106 107 let mut times_real: Vec<Second> = vec![];108 let mut times_user: Vec<Second> = vec![];109 let mut times_system: Vec<Second> = vec![];29 unmodified lines139 times_real.push(r.time_real);140 times_user.push(r.time_user);141 times_system.push(r.time_system);142 }140- } 141- // if let Some(bar) = progress_bar { bar.inc(1); }143+ }144+ if let Some(ref bar) = progress_bar {145+ bar.inc(1);146+ }147 }143- if let Some(bar) = progress_bar { bar.finish_and_clear(); }148+ if let Some(ref bar) = progress_bar {149+ bar.finish_and_clear();150+ }151 152 Ok(TimingResult {153 time_real: mean(×_real),154 time_user: mean(×_user),49 unmodified lines204 cmd: &Command<'_>,205 shell_spawning_time: TimingResult,206 options: &HyperfineOptions,207 ) -> io::Result<BenchmarkResult> {201- if options.output_style != OutputStyleOption::None { 208+ if options.output_style != OutputStyleOption::Disabled {209 println!(210 "{}{}: {}",211 "Benchmark #".bold(),212 (num + 1).to_string().bold(),20 unmodified lines233 });234 235 // Warmup phase236 if options.warmup_count > 0 {230- let mut progress_bar: Option<ProgressBar> = None;231- if options.output_style != OutputStyleOption::None { 232- progress_bar = Some(get_progress_bar(237+ let progress_bar = if options.output_style != OutputStyleOption::Disabled {238+ Some(get_progress_bar(239 options.warmup_count,240 "Performing warmup runs",241 options.output_style,236- ));237- }242+ ))243+ } else {244+ None245+ };246 247 for _ in 0..options.warmup_count {248 let _ = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;249 let _ = time_shell_command(2 unmodified lines252 options.show_output,253 options.failure_action,254 None,255 )?;248- if let Some(pbar) = progress_bar.clone() { pbar.inc(1); }256+ if let Some(ref pbar) = progress_bar {257+ pbar.inc(1);258+ }259 }250- if let Some(bar) = progress_bar { bar.finish_and_clear(); }260+ if let Some(ref bar) = progress_bar {261+ bar.finish_and_clear();262+ }263 }264 265 // Set up progress bar (and spinner for initial measurement)254- let mut progress_bar:Option<ProgressBar> = None;255-256- if options.output_style != OutputStyleOption::None { 257- progress_bar = Some(get_progress_bar(266+ let progress_bar = if options.output_style != OutputStyleOption::Disabled {267+ Some(get_progress_bar(268 options.runs.min,269 "Initial time measurement",270 options.output_style,271 ))262- }272+ } else {273+ None274+ };275 276 let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;277 278 // Initial timing run30 unmodified lines309 310 all_succeeded = all_succeeded && success;311 312 // Re-configure the progress bar301- if let Some(bar) = progress_bar.clone() { bar.set_length(count); }302- if let Some(bar) = progress_bar.clone() { bar.inc(1); }313+ if let Some(ref bar) = progress_bar {314+ bar.set_length(count);315+ bar.inc(1);316+ }317 318 // Gather statistics319 for _ in 0..count_remaining {320 run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;2 unmodified lines323 let mean = format_duration(mean(×_real), options.time_unit);324 format!("Current estimate: {}", mean.to_string().green())325 };326 313- if let Some(bar) = progress_bar.clone() { bar.set_message(&msg); }327+ if let Some(ref bar) = progress_bar {328+ bar.set_message(&msg);329+ }330 331 let (res, success) = time_shell_command(332 &options.shell,333 cmd,7 unmodified lines341 times_system.push(res.time_system);342 343 all_succeeded = all_succeeded && success;344 329- if let Some(bar) = progress_bar.clone() { bar.inc(1); }345+ if let Some(ref bar) = progress_bar {346+ bar.inc(1);347+ }348 }331- if let Some(bar) = progress_bar { bar.finish_and_clear(); }349+ if let Some(ref bar) = progress_bar {350+ bar.finish_and_clear();351+ }352 353 // Compute statistical quantities354 let t_num = times_real.len();355 let t_mean = mean(×_real);14 unmodified lines370 371 let (user_str, user_unit) = format_duration_unit(user_mean, None);372 let system_str = format_duration(system_mean, Some(user_unit));373 354- if options.output_style != OutputStyleOption::None {374+ if options.output_style != OutputStyleOption::Disabled {375 println!(376 " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",377 "mean".green().bold(),378 "σ".green(),33 unmodified lines412 } else if scores.iter().any(|&s| s > OUTLIER_THRESHOLD) {413 warnings.push(Warnings::OutliersDetected);414 }415 396- if !warnings.is_empty() && options.output_style != OutputStyleOption::None {416+ if !warnings.is_empty() {417 eprintln!(" ");418 419 for warning in &warnings {420 eprintln!(" {}: {}", "Warning".yellow(), warning);421 }422 }423 404- if options.output_style != OutputStyleOption::None { println!(" "); }424+ if options.output_style != OutputStyleOption::Disabled {425+ println!(" ");426+ }427 428 // Run cleanup command429 let cleanup_cmd =430 options21 unmodified linesmodified:src/hyperfine/types.rs+1 added-1 removed
113 unmodified lines114 /// Keep coloring, but use no progress bar115 Color,116 117 /// Disable all the output118- None,118+ Disabled,119 }120 121 /// Number of runs for a benchmark122 pub struct Runs {127 unmodified linesmodified:src/main.rs+8 added-4 removed
61 unmodified lines62 };63 64 match res {65 Ok(timing_results) => {66- let unwrapped = options.unwrap();67- if unwrapped.output_style != OutputStyleOption::None { write_benchmark_comparison(&timing_results); }68- let ans = export_manager.write_results(timing_results, unwrapped.time_unit);66+ let options = options.unwrap();67+68+ if options.output_style != OutputStyleOption::Disabled {69+ write_benchmark_comparison(&timing_results);70+ }71+72+ let ans = export_manager.write_results(timing_results, options.time_unit);73 if let Err(e) = ans {74 error(&format!(75 "The following error occurred while exporting: {}",76 e.description()62 unmodified lines139 Some("full") => OutputStyleOption::Full,140 Some("basic") => OutputStyleOption::Basic,141 Some("nocolor") => OutputStyleOption::NoColor,142 Some("color") => OutputStyleOption::Color,139- Some("none") => OutputStyleOption::None,143+ Some("none") => OutputStyleOption::Disabled,144 _ => {145 if !options.show_output && atty::is(Stream::Stdout) {146 OutputStyleOption::Full147 } else {67 unmodified lines