Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active February 18, 2016 23:29
Show Gist options
  • Save cgrand/a66fffc9f4b584c2c66f to your computer and use it in GitHub Desktop.
Save cgrand/a66fffc9f4b584c2c66f to your computer and use it in GitHub Desktop.
;; not quite an apple-to-apple comparison (merge3 and into) but the order of magnitude is correct:
;; into: 5µs
;; merge3: 17ns (yes, ns not µs)
;;
;; this huge difference comes from the fact that merge3 runtime varies with the number of modified keys (here 1)
;; while into runtime varies with the number of keys.
user=> (def e clojure.lang.PersistentHashMapKVMono/EMPTY)
(defn merge3 [anc a b fix] (clojure.lang.PersistentHashMapKVMono/merge anc a b fix))
#'user/e
#'user/merge3
user=> (let [m (into e (map (juxt identity inc) (range 500)))
m2 (assoc m 3 :b)]
(quick-bench (merge3 m m m2 prn)))
WARNING: Final GC required 9.693392873620262 % of runtime
Evaluation count : 35417754 in 6 samples of 5902959 calls.
Execution time mean : 16,714814 ns
Execution time std-deviation : 1,867584 ns
Execution time lower quantile : 15,430204 ns ( 2,5%)
Execution time upper quantile : 19,905354 ns (97,5%)
Overhead used : 1,992753 ns
Found 1 outliers in 6 samples (16,6667 %)
low-severe 1 (16,6667 %)
Variance from outliers : 31,0156 % Variance is moderately inflated by outliers
nil
user=> (let [m (into e (map (juxt identity inc) (range 500)))
m2 (assoc m 3 :b)]
(quick-bench (into m m2)))
WARNING: Final GC required 9.83322212055125 % of runtime
Evaluation count : 117474 in 6 samples of 19579 calls.
Execution time mean : 5,144252 µs
Execution time std-deviation : 83,215555 ns
Execution time lower quantile : 5,049746 µs ( 2,5%)
Execution time upper quantile : 5,245319 µs (97,5%)
Overhead used : 1,992753 ns
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment