Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Created March 11, 2013 18:56
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 pjstadig/5136670 to your computer and use it in GitHub Desktop.
Save pjstadig/5136670 to your computer and use it in GitHub Desktop.
Clojure 1.5.0-beta7
user=> (def the-atom (atom 0))
#'user/the-atom
user=> (def the-ref (ref 0))
#'user/the-ref
user=> (defn use-atom [] (swap! the-atom inc))
#'user/use-atom
user=> (defn use-ref [] (dosync (commute the-ref inc)))
#'user/use-ref
user=> (time (dotimes [_ 10000000] (use-atom)))
"Elapsed time: 305.798562 msecs"
nil
user=> (time (dotimes [_ 10000000] (use-ref)))
"Elapsed time: 6823.719408 msecs"
nil
user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment