Skip to content

Commit af7b3b1

Browse files
committed
add progress bar duration for initial time measurement and shell spawn time
closes sharkdp#416
1 parent a16781b commit af7b3b1

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/benchmark.rs

+19
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn mean_shell_spawning_time(
108108
COUNT,
109109
"Measuring shell spawning time",
110110
style,
111+
true,
111112
))
112113
} else {
113114
None
@@ -270,6 +271,7 @@ pub fn run_benchmark(
270271
options.warmup_count,
271272
"Performing warmup runs",
272273
options.output_style,
274+
false,
273275
))
274276
} else {
275277
None
@@ -299,6 +301,7 @@ pub fn run_benchmark(
299301
options.runs.min,
300302
"Initial time measurement",
301303
options.output_style,
304+
true,
302305
))
303306
} else {
304307
None
@@ -343,6 +346,22 @@ pub fn run_benchmark(
343346
all_succeeded = all_succeeded && success;
344347

345348
// Re-configure the progress bar
349+
350+
// Clear the current progress bar and set up another with eta instead of duration
351+
if let Some(bar) = progress_bar.as_ref() {
352+
bar.finish_and_clear()
353+
}
354+
let progress_bar = if options.output_style != OutputStyleOption::Disabled {
355+
Some(get_progress_bar(
356+
options.runs.min,
357+
"Current estimate: ",
358+
options.output_style,
359+
false,
360+
))
361+
} else {
362+
None
363+
};
364+
346365
if let Some(bar) = progress_bar.as_ref() {
347366
bar.set_length(count)
348367
}

src/progress_bar.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);
99
const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);
1010

1111
/// Return a pre-configured progress bar
12-
pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {
12+
pub fn get_progress_bar(
13+
length: u64,
14+
msg: &str,
15+
option: OutputStyleOption,
16+
show_duration: bool,
17+
) -> ProgressBar {
18+
let progress_bar_template = if show_duration {
19+
" {spinner} {msg:<30} {wide_bar} AT {duration_precise}"
20+
} else {
21+
" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"
22+
};
23+
1324
let progressbar_style = match option {
1425
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
1526
_ => ProgressStyle::default_spinner()
1627
.tick_chars(TICK_SETTINGS.0)
17-
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),
28+
.template(progress_bar_template),
1829
};
1930

2031
let progress_bar = match option {

0 commit comments

Comments
 (0)