Created
June 6, 2009 04:18
-
-
Save anonymous/124688 to your computer and use it in GitHub Desktop.
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
;; http://spreadsheets.google.com/ccc?key=rQLD6jgTTV5OqXwHdXtrTyg | |
(ns clj.benchmark.threadring (:gen-class)) | |
(defn relay [state hops] | |
(if (> hops 0) | |
(do (send-off (:next state) relay (dec hops)) state) | |
(do (prn (:id state)) (shutdown-agents) state))) | |
(defn agent-ring [n] | |
(let [tl (agent {:next nil :id n}) | |
hd (reduce (fn [next id] (agent {:next next :id id})) tl (reverse (range 1 n)))] | |
(send tl #(assoc % :next hd)) ;; hook up head and tail | |
(await tl) | |
hd)) | |
(defn run [n-agents hops] | |
(let [hd (agent-ring n-agents)] | |
(send-off hd relay hops) | |
:done)) | |
(defn -main [arg] | |
(run 503 (Integer/parseInt arg))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment