Using my timings macro:
https://gist.github.com/fsodomka/5890711

I am getting that:
- creation & derefing is 60% faster
- swapping is 25% faster
- resetting is about the same


;;;;;;;;;; volatile vs. atom ;;;;;;;;;;

(report
  (timings 1e7
    (deref (volatile! 42))
    (deref (atom 42))))

; |                  :expr |     :time | :ratio | :perc |
; |------------------------+-----------+--------+-------|
; | (deref (volatile! 42)) | 30.688238 |    1.0 | 39.81 |
; |      (deref (atom 42)) | 77.081141 |   2.51 | 100.0 |


(report
  (let [v (volatile! 42)
        a (atom 42)]
    (timings 1e7
      (vswap! v inc)
      (swap! a inc))))

; |          :expr |      :time | :ratio | :perc |
; |----------------+------------+--------+-------|
; | (vswap! v inc) | 136.052946 |    1.0 | 75.08 |
; |  (swap! a inc) | 181.218748 |   1.33 | 100.0 |


(report
  (let [v (volatile! 42)
        a (atom 42)]
    (timings 1e7
      (vreset! v 10)
      (reset! a 10))))

; |          :expr |     :time | :ratio | :perc |
; |----------------+-----------+--------+-------|
; |  (reset! a 10) | 98.755318 |    1.0 | 96.69 |
; | (vreset! v 10) | 102.13944 |   1.03 | 100.0 |



On Thursday, September 11, 2014 6:18:08 AM UTC+2, puzzler wrote:
>
> I'm curious: how much faster are volatiles than atoms?
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to