Skip to content

Instantly share code, notes, and snippets.

@caioaao
Created December 2, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioaao/3ae23ac783d151711669cc664619451e to your computer and use it in GitHub Desktop.
Save caioaao/3ae23ac783d151711669cc664619451e to your computer and use it in GitHub Desktop.
Benchmark: get value in nested map (2500000 iterations)
Avg(ms) vs best Code
43.279 1.00 (-> data (get :a) (get :b) (get :c))
54.564 1.26 (-> data :a :b :c)
58.446 1.35 (-> data :a :b :c identity)
76.612 1.77 (get-a-b-c data)
101.11 2.34 (compiled-select-any p data)
128.99 2.98 (select-any [(keypath :a) (keypath :b) (keypath :c)] data)
132.83 3.07 (select-any [:a :b :c] data)
134.32 3.10 (get-in data [:a :b :c])
140.66 3.25 (select-any (keypath :a :b :c) data)
161.87 3.74 (select-one [:a :b :c] data)
173.24 4.00 (select-one! [:a :b :c] data)
183.52 4.24 (select-first [:a :b :c] data)
202.88 4.69 (specter-dynamic-nested-get data :a :b :c)
********************************
Benchmark: update value in nested map (500000 iterations)
Avg(ms) vs best Code
92.933 1.00 (manual-transform data inc)
104.34 1.12 (transform [:a :b :c] inc data)
484.53 5.21 (update-in data [:a :b :c] inc)
********************************
Benchmark: transform values of a small map (500000 iterations)
Avg(ms) vs best Code
59.646 1.00 (transform MAP-VALS inc data)
87.684 1.47 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
89.256 1.50 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
89.837 1.51 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
99.288 1.66 (map-vals-map-iterable data inc)
120.96 2.03 (map-vals-map-iterable-transient data inc)
170.58 2.86 (transform [ALL LAST] inc data)
407.29 6.83 (zipmap (keys data) (map inc (vals data)))
436.34 7.32 (into {} (for [[k v] data] [k (inc v)]))
449.83 7.54 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
********************************
Benchmark: transform values of large map (600 iterations)
Avg(ms) vs best Code
89.095 1.00 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient clojure.lang.PersistentHashMap/EMPTY) data))
93.101 1.04 (transform MAP-VALS inc data)
93.748 1.05 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
111.05 1.25 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
113.96 1.28 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
127.10 1.43 (transform [ALL LAST] inc data)
132.18 1.48 (map-vals-map-iterable-transient data inc)
150.46 1.69 (map-vals-map-iterable data inc)
206.13 2.31 (into {} (for [[k v] data] [k (inc v)]))
208.74 2.34 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
227.88 2.56 (zipmap (keys data) (map inc (vals data)))
********************************
Benchmark: map a function over a vector (1000000 iterations)
Avg(ms) vs best Code
163.26 1.00 (into [] (map inc) data)
174.20 1.07 (mapv inc data)
331.13 2.03 (transform ALL inc data)
430.16 2.63 (vec (map inc data))
********************************
Benchmark: filter a sequence (500000 iterations)
Avg(ms) vs best Code
81.259 1.00 (into [] (filter even?) data)
96.245 1.18 (filterv even? data)
118.20 1.45 (doall (filter even? data))
213.72 2.63 (select [ALL even?] data)
285.84 3.52 (select-any (filterer even?) data)
********************************
Benchmark: even :a values from sequence of maps (500000 iterations)
Avg(ms) vs best Code
95.822 1.00 (into [] xf data)
108.36 1.13 (into [] (comp (map :a) (filter even?)) data)
194.83 2.03 (select [ALL :a even?] data)
227.49 2.37 (->> data (mapv :a) (filter even?) doall)
********************************
Benchmark: END on large vector (2000000 iterations)
Avg(ms) vs best Code
63.233 1.00 (conj v 1)
245.07 3.88 (reduce conj v [1])
406.59 6.43 (setval END [1] v)
********************************
Benchmark: update every value in a tree (represented with vectors) (50000 iterations)
Avg(ms) vs best Code
77.091 1.00 (tree-value-transform (fn [e] (if (even? e) (inc e) e)) data)
90.105 1.17 (transform [TreeValues even?] inc data)
110.71 1.44 (transform [TreeValuesProt even?] inc data)
255.00 3.31 (transform [(walker number?) even?] inc data)
290.60 3.77 (walk/postwalk (fn [e] (if (and (number? e) (even? e)) (inc e) e)) data)
********************************
Benchmark: transient comparison: building up vectors (8000 iterations)
Avg(ms) vs best Code
119.37 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
145.52 1.22 (setval END! toappend (transient []))
273.57 2.29 (setval END toappend [])
279.08 2.34 (reduce (fn [v i] (conj v i)) [] toappend)
********************************
Benchmark: transient comparison: building up vectors one at a time (7000 iterations)
Avg(ms) vs best Code
116.27 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
241.48 2.08 (reduce (fn [v i] (conj v i)) [] toappend)
1188.4 10.2 (reduce (fn [v i] (setval END! [i] v)) (transient []) toappend)
1553.5 13.4 (reduce (fn [v i] (setval END [i] v)) [] toappend)
********************************
Benchmark: transient comparison: assoc'ing in vectors (2500000 iterations)
Avg(ms) vs best Code
51.516 1.00 (assoc! tdata 600 0)
158.41 3.07 (assoc data 600 0)
303.07 5.88 (setval (keypath! 600) 0 tdata2)
512.64 9.95 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: assoc'ing in maps (1500000 iterations)
Avg(ms) vs best Code
97.894 1.00 (assoc! tdata 600 0)
163.59 1.67 (assoc data 600 0)
335.63 3.43 (setval (keypath! 600) 0 tdata2)
409.00 4.18 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: submap (150000 iterations)
Avg(ms) vs best Code
182.32 1.00 (transform (submap! [600 700]) modify-submap tdata)
262.25 1.44 (transform (submap [600 700]) modify-submap data)
********************************
Benchmark: set metadata (1500000 iterations)
Avg(ms) vs best Code
95.919 1.00 (with-meta data meta-map)
223.32 2.33 (setval META meta-map data)
********************************
Benchmark: get metadata (15000000 iterations)
Avg(ms) vs best Code
102.38 1.00 (meta data)
350.54 3.42 (select-any META data)
********************************
Benchmark: vary metadata (800000 iterations)
Avg(ms) vs best Code
208.59 1.00 (setval [META :y] 2 data)
234.81 1.13 (vary-meta data assoc :y 2)
********************************
Benchmark: Traverse into a set (5000 iterations)
Avg(ms) vs best Code
746.36 1.00 (set data)
830.65 1.11 (persistent! (reduce conj! (transient #{}) (traverse ALL data)))
836.39 1.12 (into #{} (traverse ALL data))
861.95 1.15 (set (select ALL data))
1208.3 1.62 (reduce conj #{} (traverse ALL data))
********************************
Benchmark: multi-transform vs. consecutive transforms, one shared nav (300000 iterations)
Avg(ms) vs best Code
242.32 1.00 (multi-transform [ALL (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
281.71 1.16 (->> data (transform [ALL even?] mult-10) (transform [ALL odd?] dec))
********************************
Benchmark: multi-transform vs. consecutive transforms, three shared navs (150000 iterations)
Avg(ms) vs best Code
267.52 1.00 (multi-transform [ALL ALL number? (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
388.98 1.45 (->> data (transform [ALL ALL number? even?] mult-10) (transform [ALL ALL number? odd?] dec))
********************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment