Database Reference
In-Depth Information
4.
For each output pixel, we need to scale it to a location in the range of the Mandelbrot
set and then get the escape point for this location:
(defn mandelbrot-pixel
([max-x max-y max-iterations set-range]
(partial mandelbrot-pixel
max-x max-y max-iterations set-range))
([max-x max-y max-iterations set-range
[pixel-x pixel-y]]
(let [[x y] (scale-point pixel-x pixel-y
max-x max-y
set-range)]
(get-escape-point x y max-iterations))))
5.
At this point, we can simply map mandelbrot-pixel over the results of
output-points . We'll also pass in the function to be used ( map or pmap ):
(defn mandelbrot
[mapper max-iterations max-x max-y set-range]
(doall
(mapper (mandelbrot-pixel
max-x max-y max-iterations set-range)
(output-points max-x max-y))))
6. Finally, we have to deine the range that the Mandelbrot set covers:
(def mandelbrot-range
{:x [-2.5, 1.0], :y [-1.0, 1.0]})
How does running this with map and pmap compare? A lot depends on the other parameters
we pass them. (For more precise and robust times, we use Criterium. See the Benchmarking
with Criterium recipe for more information on this library and how to use it.) The following is
an example output from timing map using Criterium:
user=> (quick-bench
(mandelbrot map 500 1000 1000 mandelbrot-range))
WARNING: Final GC required 1.788622983983204 % of runtime
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 20.993891 sec
Execution time std-deviation : 38.107942 ms
Execution time lower quantile : 20.971178 sec ( 2.5%)
Execution time upper quantile : 21.059463 sec (97.5%)
Overhead used : 1.817165 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 13.8889 % Variance is moderately inflated by
outliers
 
Search WWH ::




Custom Search