Skip to content

Instantly share code, notes, and snippets.

@caioaao
Created December 2, 2016 03:33
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/95a0cd834a08a777a184f5edf6c9bf00 to your computer and use it in GitHub Desktop.
Save caioaao/95a0cd834a08a777a184f5edf6c9bf00 to your computer and use it in GitHub Desktop.
Benchmark: get value in nested map (2500000 iterations)
Avg(ms) vs best Code
44.233 1.00 (-> data (get :a) (get :b) (get :c))
55.461 1.25 (-> data :a :b :c identity)
59.315 1.34 (-> data :a :b :c)
69.111 1.56 (get-a-b-c data)
119.58 2.70 (compiled-select-any p data)
126.31 2.86 (select-any [(keypath :a) (keypath :b) (keypath :c)] data)
131.44 2.97 (select-any (keypath :a :b :c) data)
134.47 3.04 (select-any [:a :b :c] data)
146.80 3.32 (get-in data [:a :b :c])
158.42 3.58 (select-one [:a :b :c] data)
158.75 3.59 (select-one! [:a :b :c] data)
168.16 3.80 (select-first [:a :b :c] data)
218.02 4.93 (specter-dynamic-nested-get data :a :b :c)
********************************
Benchmark: update value in nested map (500000 iterations)
Avg(ms) vs best Code
94.626 1.00 (manual-transform data inc)
101.58 1.07 (transform [:a :b :c] inc data)
499.86 5.28 (update-in data [:a :b :c] inc)
********************************
Benchmark: transform values of a small map (500000 iterations)
Avg(ms) vs best Code
59.640 1.00 (transform MAP-VALS inc data)
85.050 1.43 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
89.313 1.50 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
93.712 1.57 (map-vals-map-iterable data inc)
97.769 1.64 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
120.27 2.02 (map-vals-map-iterable-transient data inc)
164.80 2.76 (transform [ALL LAST] inc data)
384.86 6.45 (zipmap (keys data) (map inc (vals data)))
437.34 7.33 (into {} (for [[k v] data] [k (inc v)]))
441.37 7.40 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
********************************
Benchmark: transform values of large map (600 iterations)
Avg(ms) vs best Code
93.631 1.00 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient clojure.lang.PersistentHashMap/EMPTY) data))
100.82 1.08 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
104.31 1.11 (transform MAP-VALS inc data)
117.21 1.25 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
138.57 1.48 (map-vals-map-iterable-transient data inc)
141.28 1.51 (transform [ALL LAST] inc data)
154.98 1.66 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
178.17 1.90 (map-vals-map-iterable data inc)
216.92 2.32 (into {} (for [[k v] data] [k (inc v)]))
224.03 2.39 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
241.26 2.58 (zipmap (keys data) (map inc (vals data)))
********************************
Benchmark: map a function over a vector (1000000 iterations)
Avg(ms) vs best Code
155.83 1.00 (into [] (map inc) data)
188.84 1.21 (mapv inc data)
221.19 1.42 (transform ALL inc data)
450.74 2.89 (vec (map inc data))
********************************
Benchmark: filter a sequence (500000 iterations)
Avg(ms) vs best Code
78.342 1.00 (filterv even? data)
90.037 1.15 (into [] (filter even?) data)
121.82 1.56 (doall (filter even? data))
139.79 1.78 (select [ALL even?] data)
210.76 2.69 (select-any (filterer even?) data)
********************************
Benchmark: even :a values from sequence of maps (500000 iterations)
Avg(ms) vs best Code
93.840 1.00 (into [] xf data)
103.90 1.11 (into [] (comp (map :a) (filter even?)) data)
125.83 1.34 (select [ALL :a even?] data)
234.70 2.50 (->> data (mapv :a) (filter even?) doall)
********************************
Benchmark: END on large vector (2000000 iterations)
Avg(ms) vs best Code
67.990 1.00 (conj v 1)
270.73 3.98 (reduce conj v [1])
321.11 4.72 (setval END [1] v)
********************************
Benchmark: update every value in a tree (represented with vectors) (50000 iterations)
Avg(ms) vs best Code
78.443 1.00 (transform [TreeValuesProt even?] inc data)
85.328 1.09 (tree-value-transform (fn [e] (if (even? e) (inc e) e)) data)
98.484 1.26 (transform [TreeValues even?] inc data)
283.41 3.61 (transform [(walker number?) even?] inc data)
322.11 4.11 (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
136.45 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
155.73 1.14 (setval END! toappend (transient []))
304.53 2.23 (reduce (fn [v i] (conj v i)) [] toappend)
310.78 2.28 (setval END toappend [])
********************************
Benchmark: transient comparison: building up vectors one at a time (7000 iterations)
Avg(ms) vs best Code
133.45 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
281.51 2.11 (reduce (fn [v i] (conj v i)) [] toappend)
407.40 3.05 (reduce (fn [v i] (setval END! [i] v)) (transient []) toappend)
1219.7 9.14 (reduce (fn [v i] (setval END [i] v)) [] toappend)
********************************
Benchmark: transient comparison: assoc'ing in vectors (2500000 iterations)
Avg(ms) vs best Code
56.943 1.00 (assoc! tdata 600 0)
161.77 2.84 (assoc data 600 0)
307.41 5.40 (setval (keypath! 600) 0 tdata2)
380.44 6.68 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: assoc'ing in maps (1500000 iterations)
Avg(ms) vs best Code
101.73 1.00 (assoc! tdata 600 0)
205.11 2.02 (assoc data 600 0)
331.95 3.26 (setval (keypath! 600) 0 tdata2)
420.81 4.14 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: submap (150000 iterations)
Avg(ms) vs best Code
176.65 1.00 (transform (submap! [600 700]) modify-submap tdata)
262.64 1.49 (transform (submap [600 700]) modify-submap data)
********************************
Benchmark: set metadata (1500000 iterations)
Avg(ms) vs best Code
100.32 1.00 (with-meta data meta-map)
221.58 2.21 (setval META meta-map data)
********************************
Benchmark: get metadata (15000000 iterations)
Avg(ms) vs best Code
112.74 1.00 (meta data)
246.55 2.19 (select-any META data)
********************************
Benchmark: vary metadata (800000 iterations)
Avg(ms) vs best Code
221.94 1.00 (setval [META :y] 2 data)
248.51 1.12 (vary-meta data assoc :y 2)
********************************
Benchmark: Traverse into a set (5000 iterations)
Avg(ms) vs best Code
807.40 1.00 (into #{} (traverse ALL data))
820.43 1.02 (set data)
827.62 1.03 (persistent! (reduce conj! (transient #{}) (traverse ALL data)))
910.03 1.13 (set (select ALL data))
1179.1 1.46 (reduce conj #{} (traverse ALL data))
********************************
Benchmark: multi-transform vs. consecutive transforms, one shared nav (300000 iterations)
Avg(ms) vs best Code
203.30 1.00 (multi-transform [ALL (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
244.39 1.20 (->> 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
270.01 1.00 (multi-transform [ALL ALL number? (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
415.03 1.54 (->> 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