Skip to content

Instantly share code, notes, and snippets.

@caioaao
Created December 2, 2016 17:24
Show Gist options
  • Save caioaao/7f9c44db050aed9a5326cfd28f9efca0 to your computer and use it in GitHub Desktop.
Save caioaao/7f9c44db050aed9a5326cfd28f9efca0 to your computer and use it in GitHub Desktop.
Native implementation for CachedPathInfo
Benchmark: get value in nested map (2500000 iterations)
Avg(ms) vs best Code
42.623 1.00 (-> data (get :a) (get :b) (get :c))
49.893 1.17 (-> data :a :b :c)
53.703 1.26 (-> data :a :b :c identity)
65.554 1.54 (get-a-b-c data)
106.54 2.50 (compiled-select-any p data)
111.64 2.62 (select-any [(keypath :a) (keypath :b) (keypath :c)] data)
113.60 2.67 (select-any [:a :b :c] data)
125.56 2.95 (select-any (keypath :a :b :c) data)
137.69 3.23 (get-in data [:a :b :c])
138.32 3.25 (select-one [:a :b :c] data)
149.79 3.51 (select-one! [:a :b :c] data)
150.54 3.53 (select-first [:a :b :c] data)
176.26 4.14 (specter-dynamic-nested-get data :a :b :c)
********************************
Benchmark: update value in nested map (500000 iterations)
Avg(ms) vs best Code
93.072 1.00 (manual-transform data inc)
94.061 1.01 (transform [:a :b :c] inc data)
476.72 5.12 (update-in data [:a :b :c] inc)
********************************
Benchmark: transform values of a small map (500000 iterations)
Avg(ms) vs best Code
55.129 1.00 (transform MAP-VALS inc data)
85.570 1.55 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
90.917 1.65 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
97.378 1.77 (map-vals-map-iterable data inc)
102.16 1.85 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
121.15 2.20 (map-vals-map-iterable-transient data inc)
158.63 2.88 (transform [ALL LAST] inc data)
397.98 7.22 (zipmap (keys data) (map inc (vals data)))
432.06 7.84 (into {} (for [[k v] data] [k (inc v)]))
444.85 8.07 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
********************************
Benchmark: transform values of large map (600 iterations)
Avg(ms) vs best Code
93.279 1.00 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient clojure.lang.PersistentHashMap/EMPTY) data))
94.542 1.01 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
99.125 1.06 (transform MAP-VALS inc data)
115.68 1.24 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
119.58 1.28 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
127.24 1.36 (transform [ALL LAST] inc data)
133.90 1.44 (map-vals-map-iterable-transient data inc)
156.93 1.68 (map-vals-map-iterable data inc)
204.17 2.19 (into {} (for [[k v] data] [k (inc v)]))
212.59 2.28 (into {} (map (fn [e] [(key e) (inc (val e))]) data))
226.32 2.43 (zipmap (keys data) (map inc (vals data)))
********************************
Benchmark: map a function over a vector (1000000 iterations)
Avg(ms) vs best Code
162.95 1.00 (into [] (map inc) data)
166.61 1.02 (mapv inc data)
206.10 1.26 (transform ALL inc data)
423.14 2.60 (vec (map inc data))
********************************
Benchmark: filter a sequence (500000 iterations)
Avg(ms) vs best Code
84.177 1.00 (filterv even? data)
88.689 1.05 (into [] (filter even?) data)
125.23 1.49 (doall (filter even? data))
159.95 1.90 (select [ALL even?] data)
233.40 2.77 (select-any (filterer even?) data)
********************************
Benchmark: even :a values from sequence of maps (500000 iterations)
Avg(ms) vs best Code
88.156 1.00 (into [] xf data)
100.16 1.14 (into [] (comp (map :a) (filter even?)) data)
131.94 1.50 (select [ALL :a even?] data)
235.81 2.67 (->> data (mapv :a) (filter even?) doall)
********************************
Benchmark: END on large vector (2000000 iterations)
Avg(ms) vs best Code
67.894 1.00 (conj v 1)
271.94 4.01 (reduce conj v [1])
327.79 4.83 (setval END [1] v)
********************************
Benchmark: update every value in a tree (represented with vectors) (50000 iterations)
Avg(ms) vs best Code
81.226 1.00 (tree-value-transform (fn [e] (if (even? e) (inc e) e)) data)
85.779 1.06 (transform [TreeValuesProt even?] inc data)
102.60 1.26 (transform [TreeValues even?] inc data)
269.44 3.32 (transform [(walker number?) even?] inc data)
308.44 3.80 (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
137.48 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
156.06 1.14 (setval END! toappend (transient []))
290.63 2.11 (reduce (fn [v i] (conj v i)) [] toappend)
320.01 2.33 (setval END toappend [])
********************************
Benchmark: transient comparison: building up vectors one at a time (7000 iterations)
Avg(ms) vs best Code
122.96 1.00 (reduce (fn [v i] (conj! v i)) (transient []) toappend)
259.82 2.11 (reduce (fn [v i] (conj v i)) [] toappend)
376.03 3.06 (reduce (fn [v i] (setval END! [i] v)) (transient []) toappend)
1179.6 9.59 (reduce (fn [v i] (setval END [i] v)) [] toappend)
********************************
Benchmark: transient comparison: assoc'ing in vectors (2500000 iterations)
Avg(ms) vs best Code
60.235 1.00 (assoc! tdata 600 0)
150.60 2.50 (assoc data 600 0)
302.91 5.03 (setval (keypath! 600) 0 tdata2)
379.94 6.31 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: assoc'ing in maps (1500000 iterations)
Avg(ms) vs best Code
97.828 1.00 (assoc! tdata 600 0)
170.75 1.75 (assoc data 600 0)
314.33 3.21 (setval (keypath! 600) 0 tdata2)
392.10 4.01 (setval (keypath 600) 0 data)
********************************
Benchmark: transient comparison: submap (150000 iterations)
Avg(ms) vs best Code
184.06 1.00 (transform (submap! [600 700]) modify-submap tdata)
261.23 1.42 (transform (submap [600 700]) modify-submap data)
********************************
Benchmark: set metadata (1500000 iterations)
Avg(ms) vs best Code
99.179 1.00 (with-meta data meta-map)
210.50 2.12 (setval META meta-map data)
********************************
Benchmark: get metadata (15000000 iterations)
Avg(ms) vs best Code
109.98 1.00 (meta data)
258.15 2.35 (select-any META data)
********************************
Benchmark: vary metadata (800000 iterations)
Avg(ms) vs best Code
225.55 1.00 (setval [META :y] 2 data)
245.41 1.09 (vary-meta data assoc :y 2)
********************************
Benchmark: Traverse into a set (5000 iterations)
Avg(ms) vs best Code
761.98 1.00 (set data)
823.94 1.08 (persistent! (reduce conj! (transient #{}) (traverse ALL data)))
854.16 1.12 (into #{} (traverse ALL data))
897.03 1.18 (set (select ALL data))
1222.3 1.60 (reduce conj #{} (traverse ALL data))
********************************
Benchmark: multi-transform vs. consecutive transforms, one shared nav (300000 iterations)
Avg(ms) vs best Code
208.74 1.00 (multi-transform [ALL (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
266.18 1.28 (->> 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
283.04 1.00 (multi-transform [ALL ALL number? (multi-path [even? (terminal mult-10)] [odd? (terminal dec)])] data)
460.65 1.63 (->> 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