From 791d5c403b8d77d5d702fa9a888caa80f742ecf3 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 13 Jul 2019 14:35:19 -0700 Subject: [PATCH] Remove code to measure effect of varying numbers of threads. --- src/main.rs | 64 +++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72e9fef..4f90412 100644 --- a/src/main.rs +++ b/src/main.rs @@ -172,46 +172,38 @@ fn main() { let mut pixels = vec![0; bounds.0 * bounds.1]; - for threads in [1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 20, 30, 40, 50, 60, 70, 80, 90, - //100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 - ].iter() { - let band_rows = bounds.1 / 400; + let threads = 8; + let band_rows = bounds.1 / threads + 1; - let dt = measure_elapsed_time(|| { - let bands = Mutex::new(pixels.chunks_mut(band_rows * bounds.0).enumerate()); - crossbeam::scope(|scope| { - for i in 0..*threads { - scope.spawn(|| { - let mut count = 0; - loop { - match { - let mut guard = bands.lock().unwrap(); - guard.next() - } - { - None => { return; } - Some((i, band)) => { - count += 1; - let top = band_rows * i; - let height = band.len() / bounds.0; - let band_bounds = (bounds.0, height); - let band_upper_left = pixel_to_point(bounds, (0, top), - upper_left, lower_right); - let band_lower_right = pixel_to_point(bounds, (bounds.0, top + height), - upper_left, lower_right); - render(band, band_bounds, band_upper_left, band_lower_right); - } + { + let bands = Mutex::new(pixels.chunks_mut(band_rows * bounds.0).enumerate()); + crossbeam::scope(|scope| { + for i in 0..threads { + scope.spawn(|| { + let mut count = 0; + loop { + match { + let mut guard = bands.lock().unwrap(); + guard.next() + } + { + None => { return; } + Some((i, band)) => { + count += 1; + let top = band_rows * i; + let height = band.len() / bounds.0; + let band_bounds = (bounds.0, height); + let band_upper_left = pixel_to_point(bounds, (0, top), + upper_left, lower_right); + let band_lower_right = pixel_to_point(bounds, (bounds.0, top + height), + upper_left, lower_right); + render(band, band_bounds, band_upper_left, band_lower_right); } } - }); - } - }); + } + }); + } }); - println!("{:4} {:.3}", - threads, - dt.as_secs() as f64 + dt.subsec_nanos() as f64 * 1e-9); } write_image(&args[1], &pixels[..], bounds).expect("error writing PNG file");