New week, new Rust! What are you folks up to?
1 Like
Benchmarking a number of languages on the same task - mandelbrot.
Task is to generate a 5000x5000 mandelbrot and write the result to a text file (gnuplot matrix).
Time is in seconds - on a Macbook M1 (8 cores). All times include file I/O.
| Language | Repository | Single Thread | Multi-Thread |
|---|---|---|---|
| Awk | mandelbrot-awk | 805.9 | |
| C | mandelbrot-c | 9.1 | |
| Erlang | mandelbrot_erl | 56.0 | 16.0 |
| Fortran | mandelbrot-f | 11.6 | |
| Lua | mandelbrot-lua | 158.2 | |
| Mojo | mandelbrot-mojo | 39.6 | 39.2 |
| Nushell | mandelbrot-nu | (est) 11488.5 | |
| Python | mandelbrot-py | (pure) 177.2 | (jax) 7.5 |
| R | mandelbrot-R | 562.0 | |
| Rust | mandelbrot-rs | 8.9 | 2.5 |
| Tcl | mandelbrot-tcl | 706.1 |
1 Like
Working on blogr to add more themes and more features to make the static site generation smoother!
You can omit the allocation of the vec.
diff --git a/src/main.rs b/src/main.rs
index 390119b..9f8a28b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -115,7 +115,6 @@ fn main() {
let ur = Complex { re: xmax, im: ymax };
let mut pixels = vec![0; width * height];
- let bands: Vec<&mut [u8]> = pixels.chunks_mut(width).collect();
let render_band = |(y, band): (usize, &mut [u8])| {
let fheight = ur.im - ll.im;
@@ -130,9 +129,13 @@ fn main() {
};
if args.parallel {
- bands.into_par_iter().enumerate().for_each(render_band);
+ pixels
+ .chunks_mut(width)
+ .enumerate()
+ .par_bridge()
+ .for_each(render_band);
} else {
- bands.into_iter().enumerate().for_each(render_band);
+ pixels.chunks_mut(width).enumerate().for_each(render_band);
}
if args.gnuplot {
2 Likes
Just learned enough about generics to create a test double for my search engine!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.