-
-
Save nasser/9cd5c86a03f0b6adfc60 to your computer and use it in GitHub Desktop.
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
(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 [x stuff] | |
(bla x))) | |
;; ~15 - 21 ms | |
(time | |
(do-reduce [x stuff] | |
(bla x))) | |
;; ~13 - 24 ms | |
(time | |
(dotimes [i (count stuff)] | |
(bla (get stuff i)))) | |
;; ~58 - 63 ms | |
(time | |
(loop [i (int 0)] | |
(when (< i (count stuff)) | |
(bla (get stuff i)) | |
(recur (inc i))))) | |
;; ~65 - 68 ms | |
(time | |
(let [c (count stuff)] | |
(loop [i (int 0)] | |
(when (< i c) | |
(bla (get stuff i)) | |
(recur (inc i)))))) | |
;; ~59 - 66 ms | |
(time | |
(loop [i (int (count stuff))] | |
(when (not (zero? i)) | |
(bla (get stuff i)) | |
(recur (dec i))))) | |
;; ~75 - 82 ms | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment