(ns bench) (import '(java.util Random)) (def _keyRange 100) (def _threadCount 300) (def _repeat 100000) (def mapref1 (ref {})) (def _start (System/currentTimeMillis)) (defn fn1 [] (let [ _random (new Random ) _key (str "key" (.nextInt _random _keyRange)) ] (dosync (let [ _oldValue (get @mapref1 _key) ] (if (nil? _oldValue) (alter mapref1 assoc _key 1) (alter mapref1 assoc _key (+ 1 _oldValue)) ) ) ) ) ) (defn fn2 [ dummy ] ;(println (Thread/currentThread)) (dotimes [ _index _repeat ] (fn1) ) ) (defn fn3 [] (println (- (System/currentTimeMillis) _start)) (println @mapref1) ) (defn genAgents [] (loop [ _index 0 _agents '() ] (if (= _threadCount _index ) (do _agents ) (do (let [ _agent (agent nil) ] (recur (inc _index) (conj _agents _agent)) ) ) ) ) ) (def _agents (genAgents)) (doseq [ _agent _agents ] (send-off _agent fn2) ) (doseq [ _agent _agents ] (await _agent) ) (fn3) (shutdown-agents) (System/exit 0)