Skip to content

Instantly share code, notes, and snippets.

@killme2008
Created November 29, 2016 07:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save killme2008/8752052cee30223e3317da6ae63f3bc4 to your computer and use it in GitHub Desktop.
Clojure delay benchmark
(ns test-delay
(:import [java.util.concurrent CyclicBarrier]))
(defn benchmark-delay [threads]
(let [n (rand-int 100)
d (delay (inc n))
ret (inc n)
^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
(dotimes [_ threads]
(->
(Thread.
(fn []
(.await barrier)
(dotimes [_ 10000]
(when-not (= @d ret)
(println "deref error")))
(.await barrier)))
(.start)))
(.await barrier)
(.await barrier)
(println "ret:" ret "@d:" @d)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment