Created
April 29, 2018 08:26
-
-
Save jiacai2050/082a05394ac4ad8f59953d95519740d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns demo.specter-benchmark | |
(:use [com.rpl.specter] | |
[criterium.core])) | |
;; one big app state, look like | |
;; {app-id1 {peer-id1 #{ch-di1}}} | |
(def clients (atom {})) | |
(def num-app 10) | |
(def num-peer 20) | |
(def num-channel 5) | |
(declare rand-id) | |
(def apps (vec (take num-app (repeatedly #(str (rand-id) "-appid"))))) | |
(def peers (vec (take num-peer (repeatedly #(str (rand-id) "-peerid"))))) | |
(def channels (vec (take num-channel (repeatedly #(str (rand-id) "-chid"))))) | |
(def login-tuple (vec (for [app-id apps | |
peer-id peers | |
channel-id channels] | |
[app-id peer-id channel-id]))) | |
(defn bench-specter [] | |
(doseq [[app-id peer-id channel-id] login-tuple] | |
(setval [ATOM app-id peer-id NIL->SET (subset #{})] | |
#{channel-id} | |
clients))) | |
(def conj-set (fnil conj #{})) | |
(defn bench-vanilla-clj [] | |
(doseq [[app-id peer-id channel-id] login-tuple] | |
(swap! clients update-in [app-id peer-id] conj-set channel-id))) | |
(defn -main [& args] | |
(reset! clients {}) | |
(with-progress-reporting (quick-bench (bench-vanilla-clj))) | |
(reset! clients {}) | |
(with-progress-reporting (quick-bench (bench-specter))) | |
) | |
(def rand-id-seed | |
(mapv char (concat (range 48 58) | |
(range 65 90) | |
(range 97 123)))) | |
(defn rand-id | |
([] (rand-id 10)) | |
([len] | |
(clojure.string/join (take len (repeatedly #(rand-nth rand-id-seed)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vanilla-clj
specter