Created
November 8, 2011 20:44
-
-
Save strax/1349147 to your computer and use it in GitHub Desktop.
This file contains 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
(defn relay [x i] | |
(when (:next x) | |
(send (:next x) relay i)) | |
(when (and (zero? i) (:report-queue x)) | |
(.put (:report-queue x) i)) | |
x) | |
(defn run [m n] | |
(let [q (new java.util.concurrent.SynchronousQueue) | |
hd (reduce (fn [next _] (agent {:next next})) | |
(agent {:report-queue q}) (range (dec m)))] | |
(doseq [i (reverse (range n))] | |
(send hd relay i)) | |
(.take q))) | |
(time (run 1000 1000)) | |
->"Elapsed time: 2959.254 msecs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment