(ns bench) (import '(java.util Random)) (def _keyRange 100) (def _threadCount 300) (def _repeat 100000) (def mapref1 (ref {})) (def _start (System/currentTimeMillis)) (def _agents (seq (repeat _threadCount (agent nil)))) (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 ] (dotimes [ _index _repeat ] (fn1) ) ) (doseq [ _agent _agents ] (send-off _agent fn2) ) (defn fn3 [] (println (- (System/currentTimeMillis) _start)) (println @mapref1) ) (doseq [ _agent _agents ] (await _agent) ) (fn3) (shutdown-agents) (System/exit 0)