[][src]Struct progress_logger::ProgressLogger

pub struct ProgressLogger { /* fields omitted */ }

A tool to report the progress of computations. It can be built and configured using the builder function. If given the expected number of updates, reports the expected time to completion, based on the current throughtput.

Progress is reported every 10 seconds by default. See the examples about how to change it.

There are three methods to update the internal counter:

  • update, for events that don't happen frequently
  • update_light, which tries to report (by checking the configured frequency of updates) only once every million updates. To be used in situations where updates are frequent: it's an order of magnitude faster than update.

Reports are issued on the console using the info!() macro from the log crate. Therefore, the reports depend on your logging configuration.

Inspired by ProgressLogger in the dsiutil Java library.

Examples

Basic usage

use progress_logger::ProgressLogger;

let mut pl = ProgressLogger::builder().start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

Reporting every 5 seconds

use progress_logger::ProgressLogger;
use std::time::Duration;

let mut pl = ProgressLogger::builder()
    .with_frequency(Duration::from_secs(5))
    .start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

Changing the names of updates

use progress_logger::ProgressLogger;

let mut pl = ProgressLogger::builder()
    .with_items_name("points")
    .start();
let mut cnt = 0;
for i in 0..10000 {
    cnt += 1;
    pl.update(1u32);
}
pl.stop();

Implementations

impl ProgressLogger[src]

pub fn builder() -> ProgressLoggerBuilder[src]

Creates a builder to configure a new progress logger

pub fn time_to_completion(&self) -> Option<Duration>[src]

Get the estimated time to completion, if such prediction is available

pub fn throughput(&self) -> Option<f64>[src]

pub fn update_light<N: Into<u64>>(&mut self, cnt: N)[src]

Try to report progress only once every million updates

pub fn update<N: Into<u64>>(&mut self, cnt: N)[src]

Update the internal counter and report progress if the time since the last report is greater than the configured duration

pub fn stop(self)[src]

Stops and drops the progress logger, logging the completion statement

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.