Skip to content

Commit 8579765

Browse files
committed
further optimisation
1 parent fdd85f9 commit 8579765

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ itertools = "^0.9.0"
1616
[profile.release]
1717
#lto = "fat"
1818
#codegen-units = 1
19-
debug = true
19+
#debug = true

output.png

-17.4 KB
Loading

src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ fn main() {
5959
iterations.parse::<usize>().unwrap(),
6060
center_re,
6161
center_im,
62-
0.01,
63-
false,
62+
0.1,
63+
true,
6464
0
6565
);
6666

src/renderer.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::cmp::{min, max};
66
use std::f64::consts::LOG2_10;
77

88
use rand::seq::SliceRandom;
9-
use itertools::Itertools;
109
use rayon::prelude::*;
1110

1211
pub struct FractalRenderer {
@@ -102,12 +101,10 @@ impl FractalRenderer {
102101

103102
let time = Instant::now();
104103

105-
let indices = (0..self.image_width).cartesian_product(0..self.image_height).collect::<Vec<(usize, usize)>>();
106-
107-
let mut pixel_data = Vec::with_capacity(self.image_width * self.image_height);
108-
109-
pixel_data = indices.into_par_iter()
110-
.map(|(i, j)| {
104+
let mut pixel_data = (0..(self.image_width * self.image_height)).into_par_iter()
105+
.map(|index| {
106+
let i = index % self.image_width;
107+
let j = index / self.image_width;
111108
let element = ComplexFixed::new(i as f64 * delta_pixel + delta_top_left.re, j as f64 * delta_pixel + delta_top_left.im);
112109
let point_delta = ComplexExtended::new(element, -self.zoom.exponent);
113110
let new_delta = series_approximation.evaluate(point_delta);
@@ -157,17 +154,15 @@ impl FractalRenderer {
157154

158155
// this can be made faster, without having to do the series approximation again
159156
// this is done by storing more data in pixeldata2
160-
pixel_data.chunks_mut(1)
161-
.for_each(|pixel_data| {
162-
for data in pixel_data {
163-
data.iteration = reference.start_iteration;
164-
data.glitched = false;
165-
data.delta_current = data.delta_start - delta_z;
166-
data.delta_reference = data.delta_centre - reference_wrt_sa;
167-
// might not need the evaluate here as if we store it separately, there is no need
168-
// data.derivative_current = ComplexFixed::new(1.0, 0.0);
169-
}
170-
});
157+
pixel_data.par_iter_mut()
158+
.for_each(|pixel| {
159+
pixel.iteration = reference.start_iteration;
160+
pixel.glitched = false;
161+
pixel.delta_current = pixel.delta_start - delta_z;
162+
pixel.delta_reference = pixel.delta_centre - reference_wrt_sa;
163+
// might not need the evaluate here as if we store it separately, there is no need
164+
// data.derivative_current = ComplexFixed::new(1.0, 0.0);
165+
});
171166

172167
Perturbation::iterate(&mut pixel_data, &r, r.current_iteration);
173168

0 commit comments

Comments
 (0)