| 1 |
use indicatif::ProgressBar; |
| 2 |
|
| 3 |
fn many_units_of_easy_work(n: u64, label: &str) { |
| 4 |
let pb = ProgressBar::new(n); |
| 5 |
|
| 6 |
let mut sum = 0; |
| 7 |
for i in 0..n { |
| 8 |
// Any quick computation, followed by an update to the progress bar. |
| 9 |
sum += 2 * i + 3; |
| 10 |
pb.inc(1); |
| 11 |
} |
| 12 |
pb.finish(); |
| 13 |
|
| 14 |
println!("[{}] Sum ({}) calculated in {:?}", label, sum, pb.elapsed()); |
| 15 |
} |
| 16 |
|
| 17 |
fn main() { |
| 18 |
const N: u64 = 1 << 20; |
| 19 |
|
| 20 |
// Perform a long sequence of many simple computations monitored by a |
| 21 |
// default progress bar. |
| 22 |
many_units_of_easy_work(N, "Default progress bar "); |
| 23 |
} |