Created
November 29, 2016 07:54
-
-
Save killme2008/8752052cee30223e3317da6ae63f3bc4 to your computer and use it in GitHub Desktop.
Clojure delay benchmark
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 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