summaryrefslogtreecommitdiffstats
path: root/vendor/indicatif/examples/steady.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/indicatif/examples/steady.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/indicatif/examples/steady.rs')
-rw-r--r--vendor/indicatif/examples/steady.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/indicatif/examples/steady.rs b/vendor/indicatif/examples/steady.rs
new file mode 100644
index 000000000..4515ce97b
--- /dev/null
+++ b/vendor/indicatif/examples/steady.rs
@@ -0,0 +1,50 @@
+use std::{
+ thread::sleep,
+ time::{Duration, Instant},
+};
+
+use indicatif::{ProgressBar, ProgressIterator, ProgressStyle};
+
+fn main() {
+ let iterations = 1000;
+ // Set the array with all the blocksizes to test
+ let blocksizes: [usize; 7] = [16, 64, 256, 1024, 4096, 16384, 65536];
+
+ // Set the array with all the durations to save
+ let mut elapsed: [Duration; 7] = [Duration::ZERO; 7];
+
+ for (pos, blocksize) in blocksizes.iter().enumerate() {
+ // Set up the style for the progressbar
+ let sty = ProgressStyle::default_spinner()
+ .tick_strings(&[
+ "▹▹▹▹▹",
+ "▸▹▹▹▹",
+ "▹▸▹▹▹",
+ "▹▹▸▹▹",
+ "▹▹▹▸▹",
+ "▹▹▹▹▸",
+ "▪▪▪▪▪",
+ ])
+ .template("{prefix} {pos:>4}/{len:4} Iterations per second: {per_sec} {spinner} {msg}")
+ .unwrap();
+
+ // Set up the progress bar and apply the style
+ let pb = ProgressBar::new(iterations);
+ pb.set_style(sty);
+ pb.enable_steady_tick(Duration::from_millis(120));
+ pb.set_prefix(format!("Doing test with Blocksize {:5?}:", blocksize));
+
+ // Iterate for the given number of iterations
+ // for _ in (0..iterations) {
+ for _ in (0..iterations).progress_with(pb) {
+ // pb.inc(1);
+ // Take a timestamp for timemeasurement later on
+ let now = Instant::now();
+ sleep(Duration::from_millis(1));
+ // Save the elapsed time for later evaluation
+ elapsed[pos] += now.elapsed();
+ }
+
+ // pb.finish_using_style();
+ }
+}