Last active
March 27, 2016 23:14
-
-
Save timsgardner/71f0c22d656920f39b89 to your computer and use it in GitHub Desktop.
Revisions
-
timsgardner revised this gist
Mar 27, 2016 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,16 +16,16 @@ nil)) (time (doseq [x stuff] (bla x))) ;; ~75 - 80 ms (time (do-reduce [x stuff] (bla x))) ;; ~75 - 80 ms (time (dotimes [i (count stuff)] -
timsgardner revised this gist
Mar 27, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ (doseq [i stuff] (bla (get stuff i)))) ;; ~230 - 260 ms (time (do-reduce [i stuff] -
timsgardner created this gist
Mar 27, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ (def v (volatile! nil)) ;; a function that I don't think will get disappeared by the compiler: (defn bla [x] (vreset! v x)) (def stuff (vec (range 5e5))) (defmacro do-reduce [[x coll] & body] `(do (reduce (fn [_# ~x] ~@body nil) ~coll) nil)) (time (doseq [i stuff] (bla (get stuff i)))) ;; ~230 ms (time (do-reduce [i stuff] (bla (get stuff i)))) ;; ~220 - 260 ms (time (dotimes [i (count stuff)] (bla (get stuff i)))) ;; ~240 - 280 ms (time (loop [i (int 0)] (when (< i (count stuff)) (bla (get stuff i)) (recur (inc i))))) ;; ~280 - 300 ms (time (let [c (count stuff)] (loop [i (int 0)] (when (< i c) (bla (get stuff i)) (recur (inc i)))))) ;; ~250 - 300 ms (time (loop [i (int (count stuff))] (when (not (zero? i)) (bla (get stuff i)) (recur (dec i))))) ;; ~390 - 420 ms