Skip to content

Commit

Permalink
Set a default draw rate to decrease overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Feb 10, 2022
1 parent beb5836 commit 9df7ab3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl ProgressBar {
///
/// By default, the progress bar will redraw whenever its state advances. This setting is
/// helpful in situations where the overhead of redrawing the progress bar dominates the
/// computation whose progress is being reported.
/// computation whose progress is being reported. Setting the draw delta will override
/// the draw rate, setting it to `0`.
///
/// If `n` is greater than 0, operations that change the progress bar such as
/// [`ProgressBar::tick()`], [`ProgressBar::set_message()`] and [`ProgressBar::set_length()`]
Expand All @@ -173,12 +174,17 @@ impl ProgressBar {
pub fn set_draw_delta(&self, n: u64) {
let mut state = self.state.lock().unwrap();
state.state.draw_delta = n;
state.state.draw_rate = 0;
state.state.draw_next = state.state.pos.saturating_add(state.state.draw_delta);
}

/// Sets the refresh rate of progress bar to `n` updates per seconds
///
/// This is similar to `set_draw_delta` but automatically adapts to a constant refresh rate
/// By default, the progress bar will redraw at most 100 times per second. To disable
/// this behavior, set the draw rate to 0. The draw rate will be ignored if the draw
/// delta is set.
///
/// This setting automatically adapts the progress bar to a constant refresh rate
/// regardless of how consistent the progress is.
///
/// This parameter takes precedence on `set_draw_delta` if different from 0.
Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl ProgressState {
len,
tick: 0,
draw_delta: 0,
draw_rate: 0,
draw_rate: 100,
draw_next: 0,
status: Status::InProgress,
started: Instant::now(),
Expand Down

0 comments on commit 9df7ab3

Please sign in to comment.