Last active
August 4, 2019 00:26
-
-
Save erikkaplun/c1ef48548d581984997849ce8dda1cc7 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
user=> (defn foo [n] | |
(with-local-vars [x 0] | |
(dotimes [i n] | |
(var-set x (inc @x))))) | |
#'user/foo | |
user=> (time (foo 5000000)) | |
"Elapsed time: 514.042912 msecs" | |
user=> (time (foo 5000000)) | |
"Elapsed time: 438.661454 msecs" | |
user=> (defn bar [n] | |
(let [x (atom 0)] | |
(dotimes [i n] | |
(swap! x inc)))) | |
#'user/bar | |
user=> (time (bar 5000000)) | |
"Elapsed time: 113.794149 msecs" | |
nil | |
user=> (time (bar 5000000)) | |
"Elapsed time: 100.323271 msecs" | |
nil | |
user=> (defn baz [n] | |
(let [x (volatile! 0)] | |
(dotimes [i n] | |
(vswap! x inc)))) | |
#'user/baz | |
user=> (time (baz 5000000)) | |
"Elapsed time: 56.927072 msecs" | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment