I did this: (defn draw [#^Canvas canvas] (let [#^BufferStrategy buffer (. canvas getBufferStrategy) #^Graphics g (. buffer getDrawGraphics)] (doseq [y (range 0 *height*)] (let [dy (- 1.5 (* 2.5 (/ y *height*)))] (doseq [x (range 0 *width*)] (let [dx (- (* 3 (/ x *width*)) 2.1) value (check-bounds dx dy)] (when (> value 0) (.setColor g (Color. (* value (/ 255 *max-steps*)))) (.drawRect g x y 0 0)))) (.show buffer))) (.show buffer)))
and this: (defn check-bounds [x y] (let [px (float x) py (float y)] (loop [zx (float 0.0) zy (float 0.0) zx2 (float 0.0) zy2 (float 0.0) value (int 0)] (if (and (< value *max-steps*) (< (+ zx2 zy2) 4.0)) (let [new-zy (float (+ (* 2.0 zx zy) py)) new-zx (float (+ (- zx2 zy2) px)) new-zx2 (float (* new-zx new-zx)) new-zy2 (float (* new-zy new-zy))] (recur new-zx new-zy new-zx2 new-zy2 (inc value))) (if (== value *max-steps*) 0 value))))) and it seemed to speed up notably. On Apr 1, 11:18 pm, Dmitri <dmitri.sotni...@gmail.com> wrote: > I'm running it as a script with: > java -server -cp clojure.jar clojure.lang.Script mandelbrot.clj > > as I mentioned earlier, I did try forcing all the primitives, but > didn't notice much of a difference, I also did try running the draw > function repeatedly to make sure it wasn't just the startup times > causing it to run slow. > > (main [] > ... > > (time (draw canvas)) > (time (draw canvas)) > (time (draw canvas)))) > > as a note I also tried a jython version and it runs about twice as > fast for me, which I think is comparable, and it could just mean that > there is a > hit on performance over java that only so much can be done about. > > I'm mostly curious if I made any newbie mistakes that would cause it > to perform a lot worse than it should. I do expect pure java to run > faster in the end. > > On Apr 1, 10:49 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote: > > > On Apr 1, 9:40 pm, Dmitri <dmitri.sotni...@gmail.com> wrote: > > > > I've been playing around with rendering a mandelbrot set, and using > > > pure java it renders about 2 seconds on my machine, however it runs > > > about 10 times as slow in clojure, I was curious if I'm doing anything > > > obviously wrong, or if it's just life :) I do run it with the -server > > > flag, which does improve it a bit. I've got the java and clojure > > > source below: > > > Are you running the Clojure source as a script on the command line? > > Some of the delay may be Clojure starting up and parsing the script. > > > You should also try using primitive types in the loops. See this > > thread for > > details:http://groups.google.com/group/clojure/browse_thread/thread/61f236e83... > > > -Stuart Sierra --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---