Skip to content
Myr

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

4 files+72 added−49 removed

modified:src/hyperfine/app.rs+3 added-2 removed
133 unmodified lines
134 .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 lines
modified:src/hyperfine/benchmark.rs+62 added-45 removed
3 unmodified lines
45use colored::*;6use statistical::{mean, median, standard_deviation};78use indicatif::{ProgressBar};910use crate::hyperfine::format::{format_duration, format_duration_unit};11use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};12use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};13use crate::hyperfine::shell::execute_and_time;
81 unmodified lines
95 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 }103104 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 lines
136 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(); }144145 Ok(TimingResult {146 time_real: mean(&times_real),147 time_user: mean(&times_user),
49 unmodified lines
197 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 }209210 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 lines
226 });227228 // 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 }238239 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 lines
244 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 }252253 // 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;255256 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 }263264 let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;265266 // Initial timing run267 let (res, success) = time_shell_command(
29 unmodified lines
297298 all_succeeded = all_succeeded && success;299300 // 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); }303304 // Gather statistics305 for _ in 0..count_remaining {306 run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
1 unmodified line
308 let msg = {309 let mean = format_duration(mean(&times_real), options.time_unit);310 format!("Current estimate: {}", mean.to_string().green())311 };298 progress_bar.set_message(&msg);312313 if let Some(bar) = progress_bar.clone() { bar.set_message(&msg); }314315 let (res, success) = time_shell_command(316 &options.shell,317 cmd,318 options.show_output,
6 unmodified lines
325 times_system.push(res.time_system);326327 all_succeeded = all_succeeded && success;328314 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(); }332333 // Compute statistical quantities334 let t_num = times_real.len();335 let t_mean = mean(&times_real);
14 unmodified lines
350351 let (user_str, user_unit) = format_duration_unit(user_mean, None);352 let system_str = format_duration(system_mean, Some(user_unit));353354 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 );364349 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 }374375 // Warnings376 let mut warnings = vec![];377
22 unmodified lines
400 eprintln!(" {}: {}", "Warning".yellow(), warning);401 }402 }403387 println!(" ");404 if options.output_style != OutputStyleOption::None { println!(" "); }405406 // Run cleanup command407 let cleanup_cmd =408 options
21 unmodified lines
modified:src/hyperfine/types.rs+3 added
111 unmodified lines
112 NoColor,113114 /// Keep coloring, but use no progress bar115 Color,116117 /// Disable all the output118 None,119}120121/// Number of runs for a benchmark122pub struct Runs {
127 unmodified lines
modified:src/main.rs+4 added-2 removed
53 unmodified lines
54 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();5960 let res = match options {61 Ok(ref opts) => run(&commands, &opts),62 Err(ref e) => error(e.description()),63 };6465 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 lines
135 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