Skip to content

Instantly share code, notes, and snippets.

@trptcolin
Created April 6, 2012 16:08
Show Gist options
  • Save trptcolin/2321036 to your computer and use it in GitHub Desktop.
Save trptcolin/2321036 to your computer and use it in GitHub Desktop.
user=> (time (dotimes [i 10000000] (reduce (fn [acc [k v]] (conj acc k)) [] {:a 1 :b 2 :c 3})))
"Elapsed time: 2782.152 msecs"
nil
user=> (time (dotimes [i 10000000] (reduce-kv (fn [acc k v] (conj acc k)) [] {:a 1 :b 2 :c 3})))
"Elapsed time: 1300.516 msecs"
nil
user=> (def size 10000)
#'user/size
user=> (def h (into {} (map vector (range size) (range size))))
#'user/h
user=> (time (dotimes [i 1000] (reduce (fn [acc [k v]] (conj acc k)) [] h)))
"Elapsed time: 1901.776 msecs"
nil
user=> (time (dotimes [i 1000] (reduce-kv (fn [acc k v] (conj acc k)) [] h)))
"Elapsed time: 747.798 msecs"
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment