This commit is contained in:
Jooris Hadeler 2024-07-06 17:30:46 +00:00 committed by GitHub
commit 92c930de3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 6 deletions

View File

@ -180,6 +180,7 @@ impl<'a> Executor for ShellExecutor<'a> {
COUNT, COUNT,
"Measuring shell spawning time", "Measuring shell spawning time",
self.options.output_style, self.options.output_style,
self.options.show_elapsed,
)) ))
} else { } else {
None None
@ -214,7 +215,8 @@ impl<'a> Executor for ShellExecutor<'a> {
} }
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
bar.inc(1) bar.inc(1);
bar.reset_elapsed();
} }
} }

View File

@ -182,6 +182,7 @@ impl<'a> Benchmark<'a> {
self.options.warmup_count, self.options.warmup_count,
"Performing warmup runs", "Performing warmup runs",
self.options.output_style, self.options.output_style,
self.options.show_elapsed,
)) ))
} else { } else {
None None
@ -192,7 +193,8 @@ impl<'a> Benchmark<'a> {
let _ = self.executor.run_command_and_measure(self.command, None)?; let _ = self.executor.run_command_and_measure(self.command, None)?;
let _ = run_conclusion_command()?; let _ = run_conclusion_command()?;
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
bar.inc(1) bar.inc(1);
bar.reset_elapsed();
} }
} }
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
@ -206,6 +208,7 @@ impl<'a> Benchmark<'a> {
self.options.run_bounds.min, self.options.run_bounds.min,
"Initial time measurement", "Initial time measurement",
self.options.output_style, self.options.output_style,
self.options.show_elapsed,
)) ))
} else { } else {
None None
@ -256,7 +259,8 @@ impl<'a> Benchmark<'a> {
bar.set_length(count) bar.set_length(count)
} }
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
bar.inc(1) bar.inc(1);
bar.reset_elapsed();
} }
// Gather statistics (perform the actual benchmark) // Gather statistics (perform the actual benchmark)
@ -283,7 +287,8 @@ impl<'a> Benchmark<'a> {
all_succeeded = all_succeeded && success; all_succeeded = all_succeeded && success;
if let Some(bar) = progress_bar.as_ref() { if let Some(bar) = progress_bar.as_ref() {
bar.inc(1) bar.inc(1);
bar.reset_elapsed();
} }
run_conclusion_command()?; run_conclusion_command()?;

View File

@ -254,6 +254,17 @@ fn build_command() -> Command {
* 'mean-time': order benchmarks by mean runtime\n" * 'mean-time': order benchmarks by mean runtime\n"
), ),
) )
.arg(
Arg::new("show-elapsed")
.long("show-elapsed")
.short('E')
.action(ArgAction::SetTrue)
.help(
"Show time elapsed since the current run was started. \
This is useful for especially long benchmarks to see \
the progress the benchmark has made"
)
)
.arg( .arg(
Arg::new("time-unit") Arg::new("time-unit")
.long("time-unit") .long("time-unit")

View File

@ -239,6 +239,9 @@ pub struct Options {
/// Which time unit to use when displaying results /// Which time unit to use when displaying results
pub time_unit: Option<Unit>, pub time_unit: Option<Unit>,
/// Show elapsed time since current run start.
pub show_elapsed: bool,
} }
impl Default for Options { impl Default for Options {
@ -260,6 +263,7 @@ impl Default for Options {
command_output_policy: CommandOutputPolicy::Null, command_output_policy: CommandOutputPolicy::Null,
time_unit: None, time_unit: None,
command_input_policy: CommandInputPolicy::Null, command_input_policy: CommandInputPolicy::Null,
show_elapsed: false,
} }
} }
} }
@ -433,6 +437,10 @@ impl Options {
CommandInputPolicy::Null CommandInputPolicy::Null
}; };
if matches.get_flag("show-elapsed") {
options.show_elapsed = true;
}
Ok(options) Ok(options)
} }

View File

@ -10,12 +10,22 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);
const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200); const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);
/// 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,
show_elapsed: bool,
) -> ProgressBar {
let template_str = match show_elapsed {
true => " {spinner} {msg:<30} {wide_bar} ET {elapsed_precise} ETA {eta_precise} ",
false => " {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ",
};
let progressbar_style = match option { let progressbar_style = match option {
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(), OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
_ => ProgressStyle::default_spinner() _ => ProgressStyle::default_spinner()
.tick_chars(TICK_SETTINGS.0) .tick_chars(TICK_SETTINGS.0)
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ") .template(template_str)
.expect("no template error"), .expect("no template error"),
}; };