mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-12-02 08:04:56 +03:00
Compact output, add -s color
option, closes #70
Strip the empty lines within the results for each benchmark, but keep the empty line between each benchmark, and before the summary. Add `color` style option to show color but not be interactive (no progress bar).
This commit is contained in:
parent
4b8f47d6f2
commit
3246ec27e1
@ -100,12 +100,13 @@ 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"])
|
.possible_values(&["auto", "basic", "full", "nocolor", "color"])
|
||||||
.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.",
|
keep the interactive output without any colors. Set this to 'color to' keep \
|
||||||
|
the colors without any interactive output.",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -164,7 +164,6 @@ pub fn run_benchmark(
|
|||||||
(num + 1).to_string().bold(),
|
(num + 1).to_string().bold(),
|
||||||
cmd
|
cmd
|
||||||
);
|
);
|
||||||
println!();
|
|
||||||
|
|
||||||
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![];
|
||||||
@ -293,7 +292,6 @@ pub fn run_benchmark(
|
|||||||
user_str.blue(),
|
user_str.blue(),
|
||||||
system_str.blue()
|
system_str.blue()
|
||||||
);
|
);
|
||||||
println!(" ");
|
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
" Range ({} … {}): {:>8} … {:>8}",
|
" Range ({} … {}): {:>8} … {:>8}",
|
||||||
|
@ -12,14 +12,14 @@ pub const MIN_EXECUTION_TIME: Second = 5e-3;
|
|||||||
/// Return a pre-configured progress bar
|
/// Return a pre-configured progress bar
|
||||||
pub fn get_progress_bar(length: u64, msg: &str, option: &OutputStyleOption) -> ProgressBar {
|
pub fn get_progress_bar(length: u64, msg: &str, option: &OutputStyleOption) -> ProgressBar {
|
||||||
let progressbar_style = match *option {
|
let progressbar_style = match *option {
|
||||||
OutputStyleOption::Basic => ProgressStyle::default_bar(),
|
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
|
||||||
_ => ProgressStyle::default_spinner()
|
_ => ProgressStyle::default_spinner()
|
||||||
.tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
|
.tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")
|
||||||
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),
|
.template("\n {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let progress_bar = match *option {
|
let progress_bar = match *option {
|
||||||
OutputStyleOption::Basic => ProgressBar::hidden(),
|
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(),
|
||||||
_ => ProgressBar::new(length),
|
_ => ProgressBar::new(length),
|
||||||
};
|
};
|
||||||
progress_bar.set_style(progressbar_style.clone());
|
progress_bar.set_style(progressbar_style.clone());
|
||||||
@ -63,7 +63,7 @@ pub fn write_benchmark_comparison(results: &Vec<BenchmarkResult>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{}\n", "Summary".bold());
|
println!("{}", "Summary".bold());
|
||||||
println!(" '{}' ran", fastest_item.command.cyan());
|
println!(" '{}' ran", fastest_item.command.cyan());
|
||||||
longer_items.sort_by(|l, r| l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal));
|
longer_items.sort_by(|l, r| l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal));
|
||||||
|
|
||||||
|
@ -71,6 +71,9 @@ pub enum OutputStyleOption {
|
|||||||
|
|
||||||
/// Keep elements such as progress bar, but use no coloring
|
/// Keep elements such as progress bar, but use no coloring
|
||||||
NoColor,
|
NoColor,
|
||||||
|
|
||||||
|
/// Keep coloring, but use no progress bar
|
||||||
|
Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Number of runs for a benchmark
|
/// Number of runs for a benchmark
|
||||||
|
@ -168,6 +168,7 @@ fn build_hyperfine_options(matches: &ArgMatches) -> Result<HyperfineOptions, Opt
|
|||||||
Some("full") => OutputStyleOption::Full,
|
Some("full") => OutputStyleOption::Full,
|
||||||
Some("basic") => OutputStyleOption::Basic,
|
Some("basic") => OutputStyleOption::Basic,
|
||||||
Some("nocolor") => OutputStyleOption::NoColor,
|
Some("nocolor") => OutputStyleOption::NoColor,
|
||||||
|
Some("color") => OutputStyleOption::Color,
|
||||||
_ => {
|
_ => {
|
||||||
if !options.show_output && atty::is(Stream::Stdout) {
|
if !options.show_output && atty::is(Stream::Stdout) {
|
||||||
OutputStyleOption::Full
|
OutputStyleOption::Full
|
||||||
@ -182,8 +183,9 @@ fn build_hyperfine_options(matches: &ArgMatches) -> Result<HyperfineOptions, Opt
|
|||||||
options.output_style = OutputStyleOption::NoColor;
|
options.output_style = OutputStyleOption::NoColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.output_style != OutputStyleOption::Full {
|
match options.output_style {
|
||||||
colored::control::set_override(false);
|
OutputStyleOption::Full | OutputStyleOption::Color => colored::control::unset_override(),
|
||||||
|
_ => colored::control::set_override(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present("ignore-failure") {
|
if matches.is_present("ignore-failure") {
|
||||||
|
Loading…
Reference in New Issue
Block a user