improve performance of ALL transform on lists, add benchmark

This commit is contained in:
nathanmarz 2017-04-11 11:44:39 -04:00
parent a46ff5e8d9
commit b18a249623
2 changed files with 8 additions and 6 deletions

View file

@ -135,6 +135,13 @@
ret)))))
(let [data '(1 2 3 4 5)]
(run-benchmark "transform values of a list" 500000
(transform ALL inc data)
(sequence (map inc) data)
(reverse (into '() (map inc) data))
))
(let [data {:a 1 :b 2 :c 3 :d 4}]
(run-benchmark "transform values of a small map" 500000
(into {} (for [[k v] data] [k (inc v)]))

View file

@ -55,12 +55,7 @@
(defn- all-transform-list [structure next-fn]
;; this is done to maintain order, otherwise lists get reversed
(->> structure
(into '()
(comp (map next-fn) (filter not-NONE?)))
reverse
))
(sequence (comp (map next-fn) (filter not-NONE?)) structure))
(extend-protocol AllTransformProtocol
nil