Skip to content

Instantly share code, notes, and snippets.

@chenlilyd
Created July 6, 2022 23:43
Show Gist options
  • Save chenlilyd/3a15e953b436f549b644960b2cb68fc2 to your computer and use it in GitHub Desktop.
Save chenlilyd/3a15e953b436f549b644960b2cb68fc2 to your computer and use it in GitHub Desktop.
profile swap! conj perfromance
;; check performance of swap! with conj
(require '[clojure.core.async :as a])
(profile {:dynamic? true}
(let [ids (atom [])
n-ids 2000000
tasks (mapv (fn [i] (a/go (p :swap-conj (swap! ids conj i)))) (range n-ids))]
(doseq [t tasks]
(a/<!! t))
(assert (= n-ids (count @ids)))))
@chenlilyd
Copy link
Author

the performance is not bad, but it looks like it also requires a lot of memory, which this test does not show

pId                   nCalls        Min      50% ≤      90% ≤      95% ≤      99% ≤        Max       Mean   MAD      Clock  Total

:swap-conj         2,000,000    44.00ns   177.00ns   305.00ns   378.00ns   541.00ns     4.06s      2.23μs ±185%     4.45s     38%
:tufte/compaction          2   151.09ms   305.66ms   305.66ms   305.66ms   305.66ms   305.66ms   228.37ms  ±34%   456.75ms     4%

Accounted                                                                                                           4.91s     42%
Clock                                                                                                              11.62s    100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment