Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -E and --show-elapsed flag to show the elapsed time. #706

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/benchmark/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl<'a> Executor for ShellExecutor<'a> {
COUNT,
"Measuring shell spawning time",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
Expand Down Expand Up @@ -214,7 +215,8 @@ impl<'a> Executor for ShellExecutor<'a> {
}

if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl<'a> Benchmark<'a> {
self.options.warmup_count,
"Performing warmup runs",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
Expand All @@ -164,7 +165,8 @@ impl<'a> Benchmark<'a> {
let _ = run_preparation_command()?;
let _ = self.executor.run_command_and_measure(self.command, None)?;
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() {
Expand All @@ -178,6 +180,7 @@ impl<'a> Benchmark<'a> {
self.options.run_bounds.min,
"Initial time measurement",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
Expand Down Expand Up @@ -222,7 +225,8 @@ impl<'a> Benchmark<'a> {
bar.set_length(count)
}
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}

// Gather statistics (perform the actual benchmark)
Expand All @@ -249,7 +253,8 @@ impl<'a> Benchmark<'a> {
all_succeeded = all_succeeded && success;

if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ fn build_command() -> Command {
* '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::new("time-unit")
.long("time-unit")
Expand Down
8 changes: 8 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ pub struct Options {

/// Which time unit to use when displaying results
pub time_unit: Option<Unit>,

/// Show elapsed time since current run start.
pub show_elapsed: bool,
}

impl Default for Options {
Expand All @@ -252,6 +255,7 @@ impl Default for Options {
command_output_policy: CommandOutputPolicy::Null,
time_unit: None,
command_input_policy: CommandInputPolicy::Null,
show_elapsed: false,
}
}
}
Expand Down Expand Up @@ -419,6 +423,10 @@ impl Options {
CommandInputPolicy::Null
};

if matches.get_flag("show-elapsed") {
options.show_elapsed = true;
}

Ok(options)
}

Expand Down
14 changes: 12 additions & 2 deletions src/output/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);
const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);

/// 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 {
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
_ => ProgressStyle::default_spinner()
.tick_chars(TICK_SETTINGS.0)
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ")
.template(template_str)
.expect("no template error"),
};

Expand Down