diff --git a/src/main.rs b/src/main.rs index e37d2e1..475e116 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod sieve; use std::{ collections::HashMap, env, + sync::Arc, thread::{self, available_parallelism}, time::Instant, }; @@ -76,7 +77,6 @@ fn calculate_chunk_bounds(i: usize, num_threads: usize, max_nr: usize) -> (usize let chunk_size = max_nr / num_threads; let start = i * chunk_size; let end = ((i + 1) * chunk_size).min(max_nr); - println!("Thread {i}: {start} - {end}"); (start, end) } @@ -92,10 +92,13 @@ fn main() { let primes = get_primes(MAX_SIEVED_PRIMES); println!("{} primes. Took {:?}", primes.len(), start.elapsed()); + let primes = Arc::new(primes); + #[allow(clippy::unwrap_used)] let num_threads = available_parallelism().unwrap().get(); let mut threads = Vec::with_capacity(num_threads); + let now = Instant::now(); for i in 0..num_threads { let (start, end) = calculate_chunk_bounds(i, num_threads, max_nr); let primes = primes.clone(); @@ -118,4 +121,6 @@ fn main() { max_teilers = teilers; } } + + println!("Took {:?}", now.elapsed()); }