Added 'none' as a possible value for "style" option

This commit allows to remove all non-errornous output of the tool.
This commit is contained in:
knidarkness authored and David Peter committed 2019-10-15 17:49:48 +02:00
1 parent 6a8dd1962c
commit 5bdfdbf1cb
4 files changed
+72 -49

No files matched your search

+3 -2
View File
@@ -135,13 +135,14 @@ fn build_app() -> App<'static, 'static> {
.short("s")
.takes_value(true)
.value_name("TYPE")
.possible_values(&["auto", "basic", "full", "nocolor", "color"])
.possible_values(&["auto", "basic", "full", "nocolor", "color", "none"])
.help(
"Set output style type (default: auto). Set this to 'basic' to disable output \
coloring and interactive elements. Set it to 'full' to enable all effects \
even if no interactive terminal was detected. Set this to 'nocolor' to \
keep the interactive output without any colors. Set this to 'color' to keep \
the colors without any interactive output.",
the colors without any interactive output. Set this to 'none' to disable all \
the output of the tool.",
),
)
.arg(
+62 -45
View File
@@ -5,6 +5,8 @@ use std::process::Stdio;
use colored::*;
use statistical::{mean, median, standard_deviation};
use indicatif::{ProgressBar};
use crate::hyperfine::format::{format_duration, format_duration_unit};
use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};
use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};
@@ -94,7 +96,10 @@ pub fn mean_shell_spawning_time(
show_output: bool,
) -> io::Result<TimingResult> {
const COUNT: u64 = 200;
let progress_bar = get_progress_bar(COUNT, "Measuring shell spawning time", style);
let mut progress_bar: Option<ProgressBar> = None;
if style != OutputStyleOption::None {
progress_bar = Some(get_progress_bar(COUNT, "Measuring shell spawning time", style));
}
let mut times_real: Vec<Second> = vec![];
let mut times_user: Vec<Second> = vec![];
@@ -132,10 +137,10 @@ pub fn mean_shell_spawning_time(
times_user.push(r.time_user);
times_system.push(r.time_system);
}
}
progress_bar.inc(1);
}
// if let Some(bar) = progress_bar { bar.inc(1); }
}
progress_bar.finish_and_clear();
if let Some(bar) = progress_bar { bar.finish_and_clear(); }
Ok(TimingResult {
time_real: mean(&times_real),
@@ -193,12 +198,14 @@ pub fn run_benchmark(
shell_spawning_time: TimingResult,
options: &HyperfineOptions,
) -> io::Result<BenchmarkResult> {
println!(
"{}{}: {}",
"Benchmark #".bold(),
(num + 1).to_string().bold(),
cmd
);
if options.output_style != OutputStyleOption::None {
println!(
"{}{}: {}",
"Benchmark #".bold(),
(num + 1).to_string().bold(),
cmd
);
}
let mut times_real: Vec<Second> = vec![];
let mut times_user: Vec<Second> = vec![];
@@ -220,11 +227,14 @@ pub fn run_benchmark(
// Warmup phase
if options.warmup_count > 0 {
let progress_bar = get_progress_bar(
options.warmup_count,
"Performing warmup runs",
options.output_style,
);
let mut progress_bar: Option<ProgressBar> = None;
if options.output_style != OutputStyleOption::None {
progress_bar = Some(get_progress_bar(
options.warmup_count,
"Performing warmup runs",
options.output_style,
));
}
for _ in 0..options.warmup_count {
let _ = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
@@ -235,17 +245,21 @@ pub fn run_benchmark(
options.failure_action,
None,
)?;
progress_bar.inc(1);
if let Some(pbar) = progress_bar.clone() { pbar.inc(1); }
}
progress_bar.finish_and_clear();
if let Some(bar) = progress_bar { bar.finish_and_clear(); }
}
// Set up progress bar (and spinner for initial measurement)
let progress_bar = get_progress_bar(
options.runs.min,
"Initial time measurement",
options.output_style,
);
let mut progress_bar:Option<ProgressBar> = None;
if options.output_style != OutputStyleOption::None {
progress_bar = Some(get_progress_bar(
options.runs.min,
"Initial time measurement",
options.output_style,
))
}
let prepare_res = run_preparation_command(&options.shell, &prepare_cmd, options.show_output)?;
@@ -284,8 +298,8 @@ pub fn run_benchmark(
all_succeeded = all_succeeded && success;
// Re-configure the progress bar
progress_bar.set_length(count);
progress_bar.inc(1);
if let Some(bar) = progress_bar.clone() { bar.set_length(count); }
if let Some(bar) = progress_bar.clone() { bar.inc(1); }
// Gather statistics
for _ in 0..count_remaining {
@@ -295,7 +309,8 @@ pub fn run_benchmark(
let mean = format_duration(mean(&times_real), options.time_unit);
format!("Current estimate: {}", mean.to_string().green())
};
progress_bar.set_message(&msg);
if let Some(bar) = progress_bar.clone() { bar.set_message(&msg); }
let (res, success) = time_shell_command(
&options.shell,
@@ -311,9 +326,9 @@ pub fn run_benchmark(
all_succeeded = all_succeeded && success;
progress_bar.inc(1);
if let Some(bar) = progress_bar.clone() { bar.inc(1); }
}
progress_bar.finish_and_clear();
if let Some(bar) = progress_bar { bar.finish_and_clear(); }
// Compute statistical quantities
let t_num = times_real.len();
@@ -336,24 +351,26 @@ pub fn run_benchmark(
let (user_str, user_unit) = format_duration_unit(user_mean, None);
let system_str = format_duration(system_mean, Some(user_unit));
println!(
" Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
"mean".green().bold(),
"σ".green(),
mean_str.green().bold(),
stddev_str.green(),
user_str.blue(),
system_str.blue()
);
if options.output_style != OutputStyleOption::None {
println!(
" Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
"mean".green().bold(),
"σ".green(),
mean_str.green().bold(),
stddev_str.green(),
user_str.blue(),
system_str.blue()
);
println!(
" Range ({} … {}): {:>8} … {:>8} {}",
"min".cyan(),
"max".purple(),
min_str.cyan(),
max_str.purple(),
num_str.dimmed()
);
println!(
" Range ({} … {}): {:>8} … {:>8} {}",
"min".cyan(),
"max".purple(),
min_str.cyan(),
max_str.purple(),
num_str.dimmed()
);
}
// Warnings
let mut warnings = vec![];
@@ -384,7 +401,7 @@ pub fn run_benchmark(
}
}
println!(" ");
if options.output_style != OutputStyleOption::None { println!(" "); }
// Run cleanup command
let cleanup_cmd =
+3
View File
@@ -113,6 +113,9 @@ pub enum OutputStyleOption {
/// Keep coloring, but use no progress bar
Color,
/// Disable all the output
None,
}
/// Number of runs for a benchmark
+4 -2
View File
@@ -55,6 +55,7 @@ fn main() {
let options = build_hyperfine_options(&matches);
let export_manager = build_export_manager(&matches);
let commands = build_commands(&matches);
let unwrapped_opts = options.unwrap();
let res = match options {
Ok(ref opts) => run(&commands, &opts),
@@ -63,8 +64,8 @@ fn main() {
match res {
Ok(timing_results) => {
write_benchmark_comparison(&timing_results);
let ans = export_manager.write_results(timing_results, options.unwrap().time_unit);
if unwrapped_opts.output_style != OutputStyleOption::None { write_benchmark_comparison(&timing_results); }
let ans = export_manager.write_results(timing_results, unwrapped_opts.time_unit);
if let Err(e) = ans {
error(&format!(
"The following error occurred while exporting: {}",
@@ -135,6 +136,7 @@ fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions,
Some("basic") => OutputStyleOption::Basic,
Some("nocolor") => OutputStyleOption::NoColor,
Some("color") => OutputStyleOption::Color,
Some("none") => OutputStyleOption::None,
_ => {
if !options.show_output && atty::is(Stream::Stdout) {
OutputStyleOption::Full