Advertisement
Guest User

Untitled

a guest
Aug 30th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn run
  2.   [nvecs nitems nthreads niters]
  3.   (let [vec-refs
  4.         (->> (* nvecs nitems)
  5.              (range)
  6.              (into [] (comp (partition-all nitems)
  7.                             (map vec)
  8.                             (map ref))))
  9.  
  10.         swap
  11.         #(let [v1 (rand-int nvecs)
  12.                v2 (rand-int nvecs)
  13.                i1 (rand-int nitems)
  14.                i2 (rand-int nitems)]
  15.           (dosync
  16.             (let [tmp (nth @(vec-refs v1) i1)]
  17.               (alter (vec-refs v1) assoc i1 (nth @(vec-refs v2) i2))
  18.               (alter (vec-refs v2) assoc i2 tmp))))
  19.  
  20.         report
  21.         #(->> vec-refs
  22.               (into [] (comp (map deref)
  23.                              (map (fn [v] (prn v) v))
  24.                              cat
  25.                              (distinct)))
  26.               (count)
  27.               (println "Distinct:"))]
  28.  
  29.     (report)
  30.  
  31.     (->> #(dotimes [_ niters] (swap))
  32.          (repeat nthreads)
  33.          (apply pcalls)
  34.          (dorun))
  35.  
  36.     (report)))
  37.  
  38. (run 100 10 10 100000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement