Created
July 18, 2016 19:22
-
-
Save johnmarinelli/adc5533c19fb0b6d74cf4ef04ae55ee6 to your computer and use it in GitHub Desktop.
why isn't `julia-subrect-opt` showing signs of a performance increase, when the its constituent function (for-each-pixel) does?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn for-each-pixel [constant max-itrs radius r-min x-step y-step px] | |
(let [[j i] px | |
[x y] (normalize-coords (double j) (double i) r-min x-step y-step) | |
z (->Complex x y) | |
zitrs (sq-poly-iteration z constant max-itrs radius) | |
idx (dec (count zitrs))] | |
(when (> idx @impure/max-idx) | |
(reset! impure/max-idx idx)) | |
[j i idx])) | |
;(bench (julia/for-each-pixel (->Complex rc ic) max-itrs radius r-min x-step y-step [xt yt]))) | |
;Evaluation count : 3825300 in 60 samples of 63755 calls. | |
;Execution time mean : 16.018466 µs | |
(defn for-each-pixel-opt [[^double r0 ^double i0] [max-itrs radius r-min] [^double x-step ^double y-step] [^double j ^double i]] | |
(let [[x y] (normalize-coords j i r-min x-step y-step) | |
zitrs (sq-poly-iteration-opt x y [r0 i0 max-itrs radius]) | |
idx (count zitrs)] | |
(when (> idx @impure/max-idx) | |
(reset! impure/max-idx idx)) | |
[j i idx])) | |
;(bench (julia/for-each-pixel-opt [rc ic] [max-itrs radius r-min] [x-step y-step] [xt yt]))) | |
;Evaluation count : 59542860 in 60 samples of 992381 calls. | |
;Execution time mean : 1.038955 µs | |
(defn julia-subrect [^Long start-x ^Long start-y ^Long end-x ^Long end-y ^Long total-width ^Long total-height ^Complex constant ^Long max-itrs] | |
(let [grid (for [y (range start-y end-y)] | |
(vec (for [x (range start-x end-x)] | |
[x y]))) | |
radius (calculate-r constant) | |
r-min (- radius) | |
r-max radius | |
x-step (/ (Math/abs (- r-max r-min)) total-width) | |
y-step (/ (Math/abs (- r-max r-min)) total-height) | |
calculate-pixel (partial for-each-pixel constant max-itrs radius r-min x-step y-step) | |
for-each-row (fn [r] (map calculate-pixel r))] | |
(map for-each-row grid))) | |
;(bench (doall (julia/julia-subrect start-x start-y end-x end-y total-width total-height c max-itrs)))) | |
;Evaluation count : 22080 in 60 samples of 368 calls. | |
;Execution time mean : 2.746852 ms | |
(defn julia-subrect-opt [[^long start-x ^long start-y ^long end-x ^long end-y] [^double rc ^double ic] total-width total-height max-itrs ] | |
(let [grid (for [y (range start-y end-y)] | |
(vec (for [x (range start-x end-x)] | |
[x y]))) | |
radius (calculate-r-opt rc ic) | |
r-min (- radius) | |
r-max radius | |
x-step (/ (Math/abs (- r-max r-min)) total-width) | |
y-step (/ (Math/abs (- r-max r-min)) total-height) | |
calculate-pixel (fn [px] (for-each-pixel-opt [rc ic] [max-itrs radius r-min] [x-step y-step] px)) | |
for-each-row (fn [r] (map calculate-pixel r))] | |
(map for-each-row grid))) | |
;(bench (doall (julia/julia-subrect-opt [start-x start-y end-x end-y] [rc ic] total-width total-height max-itrs)))) | |
;Evaluation count : 21720 in 60 samples of 362 calls. | |
;Execution time mean : 2.831553 ms | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment