Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created August 14, 2013 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcromartie/6233620 to your computer and use it in GitHub Desktop.
Save jcromartie/6233620 to your computer and use it in GitHub Desktop.
(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