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