Skip to content

Instantly share code, notes, and snippets.

@strax
Created November 8, 2011 20:44
Show Gist options
  • Save strax/1349147 to your computer and use it in GitHub Desktop.
Save strax/1349147 to your computer and use it in GitHub Desktop.
(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