Added 'none' as a possible value for "style" option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This commit allows to remove all non-errornous output of the tool.
authored by knidarkness · committed by David Peter · parent 6a8dd19 · Browse files · 4 files·+72 added−49 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+72 added−49 removed
- other:+72 added−49 removed
Provenance
- Commit
5bdfdbf- Tree
38e20cc- Author
knidarkness <knidarkness@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
6a8dd19
4 files changed+72 added−49 removed
modified:src/hyperfine/app.rs+3 added-2 removed
133 unmodified lines134 .long("style")135 .short("s")136 .takes_value(true)137 .value_name("TYPE")138- .possible_values(&["auto", "basic", "full", "nocolor", "color"])138+ .possible_values(&["auto", "basic", "full", "nocolor", "color", "none"])139 .help(140 "Set output style type (default: auto). Set this to 'basic' to disable output \141 coloring and interactive elements. Set it to 'full' to enable all effects \142 even if no interactive terminal was detected. Set this to 'nocolor' to \143 keep the interactive output without any colors. Set this to 'color' to keep \144- the colors without any interactive output.",144+ the colors without any interactive output. Set this to 'none' to disable all \145+ the output of the tool.",146 ),147 )148 .arg(149 Arg::with_name("shell")65 unmodified linesmodified:src/hyperfine/benchmark.rs+62 added-45 removed
3 unmodified lines4 5 use colored::*;6 use statistical::{mean, median, standard_deviation};7 8+use indicatif::{ProgressBar};9+10 use crate::hyperfine::format::{format_duration, format_duration_unit};11 use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};12 use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};13 use crate::hyperfine::shell::execute_and_time;81 unmodified lines95 style: OutputStyleOption,96 show_output: bool,97 ) -> io::Result<TimingResult> {98 const COUNT: u64 = 200;97- let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time", style);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+ }103 104 let mut times_real: Vec<Second> = vec![];105 let mut times_user: Vec<Second> = vec![];106 let mut times_system: Vec<Second> = vec![];29 unmodified lines136 times_real.push(r.time_real);137 times_user.push(r.time_user);138 times_system.push(r.time_system);139 }135- }136- progress_bar.inc(1);140+ } 141+ // if let Some(bar) = progress_bar { bar.inc(1); }142 }138- progress_bar.finish_and_clear();143+ if let Some(bar) = progress_bar { bar.finish_and_clear(); }144 145 Ok(TimingResult {146 time_real: mean(×_real),147 time_user: mean(×_user),49 unmodified lines197 cmd: &Command<'_>,198 shell_spawning_time: TimingResult,199 options: &HyperfineOptions,200 ) -> io::Result<BenchmarkResult> {201+ if options.output_style != OutputStyleOption::None { 196- println!(197- "{}{}: {}",198- "Benchmark #".bold(),199- (num + 1).to_string().bold(),200- cmd201- );202+ println!(203+ "{}{}: {}",204+ "Benchmark #".bold(),205+ (num + 1).to_string().bold(),206+ cmd207+ );208+ }209 210 let mut times_real: Vec<Second> = vec![];211 let mut times_user: Vec<Second> = vec![];212 let mut times_system: Vec<Second> = vec![];13 unmodified lines226 });227 228 // Warmup phase229 if options.warmup_count > 0 {230+ let mut progress_bar: Option<ProgressBar> = None;231+ if options.output_style != OutputStyleOption::None { 223- let progress_bar = get_progress_bar(224- options.warmup_count,225- "Performing warmup runs",226- options.output_style,227- );232+ progress_bar = Some(get_progress_bar(233+ options.warmup_count,234+ "Performing warmup runs",235+ options.output_style,236+ ));237+ }238 239 for _ in 0..options.warmup_count {240 let _ = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;241 let _ = time_shell_command(2 unmodified lines244 options.show_output,245 options.failure_action,246 None,247 )?;238- progress_bar.inc(1);248+ if let Some(pbar) = progress_bar.clone() { pbar.inc(1); }249 }240- progress_bar.finish_and_clear();250+ if let Some(bar) = progress_bar { bar.finish_and_clear(); }251 }252 253 // Set up progress bar (and spinner for initial measurement)244- let progress_bar = get_progress_bar(245- options.runs.min,246- "Initial time measurement",247- options.output_style,248- );254+ let mut progress_bar:Option<ProgressBar> = None;255 256+ if options.output_style != OutputStyleOption::None { 257+ progress_bar = Some(get_progress_bar(258+ options.runs.min,259+ "Initial time measurement",260+ options.output_style,261+ ))262+ }263+264 let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;265 266 // Initial timing run267 let (res, success) = time_shell_command(29 unmodified lines297 298 all_succeeded = all_succeeded && success;299 300 // Re-configure the progress bar287- progress_bar.set_length(count);288- progress_bar.inc(1);301+ if let Some(bar) = progress_bar.clone() { bar.set_length(count); }302+ if let Some(bar) = progress_bar.clone() { bar.inc(1); }303 304 // Gather statistics305 for _ in 0..count_remaining {306 run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;1 unmodified line308 let msg = {309 let mean = format_duration(mean(×_real), options.time_unit);310 format!("Current estimate: {}", mean.to_string().green())311 };298- progress_bar.set_message(&msg);312 313+ if let Some(bar) = progress_bar.clone() { bar.set_message(&msg); }314+315 let (res, success) = time_shell_command(316 &options.shell,317 cmd,318 options.show_output,6 unmodified lines325 times_system.push(res.time_system);326 327 all_succeeded = all_succeeded && success;328 314- progress_bar.inc(1);329+ if let Some(bar) = progress_bar.clone() { bar.inc(1); }330 }316- progress_bar.finish_and_clear();331+ if let Some(bar) = progress_bar { bar.finish_and_clear(); }332 333 // Compute statistical quantities334 let t_num = times_real.len();335 let t_mean = mean(×_real);14 unmodified lines350 351 let (user_str, user_unit) = format_duration_unit(user_mean, None);352 let system_str = format_duration(system_mean, Some(user_unit));353 354+ if options.output_style != OutputStyleOption::None {339- println!(340- " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",341- "mean".green().bold(),342- "σ".green(),343- mean_str.green().bold(),344- stddev_str.green(),345- user_str.blue(),346- system_str.blue()347- );355+ println!(356+ " Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",357+ "mean".green().bold(),358+ "σ".green(),359+ mean_str.green().bold(),360+ stddev_str.green(),361+ user_str.blue(),362+ system_str.blue()363+ );364 349- println!(350- " Range ({} … {}): {:>8} … {:>8} {}",351- "min".cyan(),352- "max".purple(),353- min_str.cyan(),354- max_str.purple(),355- num_str.dimmed()356- );365+ println!(366+ " Range ({} … {}): {:>8} … {:>8} {}",367+ "min".cyan(),368+ "max".purple(),369+ min_str.cyan(),370+ max_str.purple(),371+ num_str.dimmed()372+ );373+ }374 375 // Warnings376 let mut warnings = vec![];377 22 unmodified lines400 eprintln!(" {}: {}", "Warning".yellow(), warning);401 }402 }403 387- println!(" ");404+ if options.output_style != OutputStyleOption::None { println!(" "); }405 406 // Run cleanup command407 let cleanup_cmd =408 options21 unmodified linesmodified:src/hyperfine/types.rs+3 added
111 unmodified lines112 NoColor,113 114 /// Keep coloring, but use no progress bar115 Color,116+117+ /// Disable all the output118+ None,119 }120 121 /// Number of runs for a benchmark122 pub struct Runs {127 unmodified linesmodified:src/main.rs+4 added-2 removed
53 unmodified lines54 let matches = get_arg_matches(env::args_os());55 let options = build_hyperfine_options(&matches);56 let export_manager = build_export_manager(&matches);57 let commands = build_commands(&matches);58+ let unwrapped_opts = options.unwrap();59 60 let res = match options {61 Ok(ref opts) => run(&commands, &opts),62 Err(ref e) => error(e.description()),63 };64 65 match res {66 Ok(timing_results) => {66- write_benchmark_comparison(&timing_results);67- let ans = export_manager.write_results(timing_results, options.unwrap().time_unit);67+ if unwrapped_opts.output_style != OutputStyleOption::None { write_benchmark_comparison(&timing_results); }68+ let ans = export_manager.write_results(timing_results, unwrapped_opts.time_unit);69 if let Err(e) = ans {70 error(&format!(71 "The following error occurred while exporting: {}",72 e.description()62 unmodified lines135 Some("full") => OutputStyleOption::Full,136 Some("basic") => OutputStyleOption::Basic,137 Some("nocolor") => OutputStyleOption::NoColor,138 Some("color") => OutputStyleOption::Color,139+ Some("none") => OutputStyleOption::None,140 _ => {141 if !options.show_output && atty::is(Stream::Stdout) {142 OutputStyleOption::Full143 } else {67 unmodified lines