Created
August 14, 2013 17:53
-
-
Save jcromartie/6233620 to your computer and use it in GitHub Desktop.
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 characters
(ns speedtest) | |
(defn with-args | |
"Count down from n, return 0" | |
[n] | |
(if (< 0 n) | |
(recur (dec n)) | |
0)) | |
(defn with-state | |
"Count down from n, return 0" | |
[n] | |
(let [state (atom n) | |
work (fn [] | |
(if (< 0 @state) | |
(do | |
(swap! state dec) | |
(recur)) | |
0))] | |
(work))) | |
;; speedtest> (time (with-args 1e8)) | |
;; "Elapsed time: 1291.392 msecs" | |
;; 0 | |
;; speedtest> (time (with-state 1e8)) | |
;; "Elapsed time: 3027.813 msecs" | |
;; 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment