From 25d06948b4240a369643efbfae36498eeceecbc3 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Thu, 2 May 2024 10:39:48 +0200 Subject: [PATCH] added progress bar --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21064af..fd034bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,8 @@ mod plot; const THREAD_CNT: usize = 8; const SAMPLE_LIMIT: usize = 1_000_000_000; -const SUB_SAMPLES: Vec = vec![1, 2, 5]; -const SAMPLES_PER_ITERATION: usize = 1; +const SUB_SAMPLES: [usize; 3] = [1, 2, 5]; +const SAMPLES_PER_ITERATION: usize = 10; fn main() { let bounds: Bounds = Bounds::new(LinearBounds::new(0_f64, 20_f64), LinearBounds::new(-100_f64, 150000_f64)); @@ -27,15 +27,18 @@ fn main() { while sample_cnt < SAMPLE_LIMIT { for sub_sample in SUB_SAMPLES.clone() { let samples: usize = sub_sample * sample_cnt; - for _ in 0..SAMPLES_PER_ITERATION { + for sample in 0..SAMPLES_PER_ITERATION { result.add_sample(samples, func.approximate(&bounds, samples, THREAD_CNT)); + let progress: usize = (((sample + 1) as f64 / SAMPLES_PER_ITERATION as f64) * 25.0) as usize; + eprint!("\r{:12} [{}{}]", samples, "|".repeat(progress), " ".repeat(25 - progress)); } + println!(); } sample_cnt *= 10; } result.print(); - let mut file: io::Result = File::create("output.json"); + let file: io::Result = File::create("output.json"); if file.is_err() { panic!("Error creating output file") }