![]() ![]() Here is my updated code, am I moving in the right direction or way off the mark here? (ns gol.core I then put this at the top of my code: (set! *unchecked-math* :warn-on-boxed)Īnd fixed all the warnings, but I'm still seeing no difference in performance. I started by trying to guess where the bottlenecks are and wrapping the values involved with (long x) etc but wasn't making much progress. Private static int globalBoard = new int Private static final int maxFrameDuration = 1000/frameCap Private static final int windowHeight = statusBarHeight + (hCells * cellSize) Private static final int windowWidth = wCells * cellSize Private static final int statusBarHeight = 20 Private static final Color cellColor = new Color(0,255,0) (def t (timer (fn (repaint! m-canvas)) :delay 1)) :width (+ 3 windowWidth), :height (inc windowHeight), (reset! globalBoard (vec2d wCells hCells (fn (gol board )))) (.drawString g (str "Simulations per second: " (fps)) 50 (- windowHeight 5)) (.fillRect g (* cellSize i) (* cellSize j) cellSize cellSize)) (.drawRect g 0 0 windowWidth (- windowHeight statusBarHeight)) (double (/ 1000 (- (System/currentTimeMillis) previous))))) (reset! lastTime (System/currentTimeMillis)) (when (pos? toSleep) (Thread/sleep toSleep)) (let [previous (System/currentTimeMillis) N (count (filter pos? (neighbors board p)))] ![]() (def lastTime (atom (System/currentTimeMillis))) (def globalBoard (atom (vec2d wCells hCells (fn (rand-int 2))))) (mapv (fn(mapv (fn (fun x y)) (range sx))) (range sy))) (def maxFrameDuration (quot 1000 frameCap)) (def windowHeight (+ statusBarHeight (* hCells cellSize))) ![]() I know there are faster algorithms for Conway's game of life but right now I'm mostly interested in trying to get to grips with how Clojure works and thought the naive algo would be the best starting point. I'm using seesaw for the Clojure version and regular Swing for the java version. Can any Clojure pros here tell me where I'm going wrong? This is my first non trivial clojure program and I think the problem must be me not using clojure correctly rather than clojure being this much slower. I'm measuring the number of simulation steps per second and my Java version can easily go as high as 1000 steps per second, but my clojure version barely hits 4 steps per second. I have written a simple implementation of Conway's game of life in both Clojure and Java, trying to keep the overall structure of the code as similar as possible to make them easy to compare. I'm trying to learn Clojure coming from a Java background. Nightcode - a beginner friendly Clojure editor.Counterclockwise - Clojure support for Eclipse.(clj-templates) - templates for Leiningen and Boot.The Clojure Toolbox - a list of popular Clojure libraries.Gorilla REPL - A rich REPL for Clojure in the notebook style.Clojureverse: a forum for and by the Clojure community. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |