Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn run
- [nvecs nitems nthreads niters]
- (let [vec-refs
- (->> (* nvecs nitems)
- (range)
- (into [] (comp (partition-all nitems)
- (map vec)
- (map ref))))
- swap
- #(let [v1 (rand-int nvecs)
- v2 (rand-int nvecs)
- i1 (rand-int nitems)
- i2 (rand-int nitems)]
- (dosync
- (let [tmp (nth @(vec-refs v1) i1)]
- (alter (vec-refs v1) assoc i1 (nth @(vec-refs v2) i2))
- (alter (vec-refs v2) assoc i2 tmp))))
- report
- #(->> vec-refs
- (into [] (comp (map deref)
- (map (fn [v] (prn v) v))
- cat
- (distinct)))
- (count)
- (println "Distinct:"))]
- (report)
- (->> #(dotimes [_ niters] (swap))
- (repeat nthreads)
- (apply pcalls)
- (dorun))
- (report)))
- (run 100 10 10 100000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement