Number of physical cores: 8Vectorized: 14.634963190184047 msParallelized: 4.1496295025728989 msParallel speedup: 3.5268120156534257
Number of physical cores: 8Vectorized: 14.634963190184047 msParallelized: 4.1496295025728989 msParallel speedup: 3.5268120156534257
I am trying to write the most basic python code to compare. I wrote this:
MAX_ITERS = 1000def mandelbrot_kernel(c): z = c nv = 0 for i in range(MAX_ITERS): if abs(z) > 2: break z = z*z + c nv += 1 return nvheight = 4096width = 4096min_x = -2.0max_x = 0.47min_y = -1.12max_y = 1.12scalex = (max_x - min_x) / widthscaley = (max_y - min_y) / heightoutput = [[0 for x in range(width)] for y in range(height)]for h in range(height): cy = min_y + h * scaley for w in range(width): cx = min_x + w * scalex output[w][h] = mandelbrot_kernel(complex(cx, cy))
MAX_ITERS = 1000def mandelbrot_kernel(c): z = c nv = 0 for i in range(MAX_ITERS): if abs(z) > 2: break z = z*z + c nv += 1 return nvheight = 4096width = 4096min_x = -2.0max_x = 0.47min_y = -1.12max_y = 1.12scalex = (max_x - min_x) / widthscaley = (max_y - min_y) / heightoutput = [[0 for x in range(width)] for y in range(height)]for h in range(height): cy = min_y + h * scaley for w in range(width): cx = min_x + w * scalex output[w][h] = mandelbrot_kernel(complex(cx, cy))
But that python code takes 7 minutes to run. This is 30285x slower than the vectorized code. Am I doing this right? The page only claimed an 89x but maybe the blog post has not yet been written to explain the vectorized code speed up?