Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active August 29, 2015 14:24
Show Gist options
  • Save cgrand/48363d7f58477a35ce69 to your computer and use it in GitHub Desktop.
Save cgrand/48363d7f58477a35ce69 to your computer and use it in GitHub Desktop.
kvbitmap vs master
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 1 column, instead of 6. in line 4.
PersistentHashMap benchmark: kvbitmap vs master
results are kvbitmap runtime / master runtime
below 100% kvbitmap is faster
above 100% master is faster
size assoc! assoc get dissoc dissoc!
16 84,64% 91,21% 96,56% 99,84% 89,91%
64 80,12% 91,66% 98,66% 104,97% 92,78%
256 89,37% 99,33% 97,59% 111,69% 98,20%
1024 75,94% 86,75% 105,88% 110,11% 113,55%
4096 100,04% 103,97% 102,06% 113,72% 109,04%
16384 91,80% 93,55% 99,06% 114,34% 105,96%
65536 74,37% 81,30% 80,16% 99,82% 88,88%
262144 90,27% 83,95% 86,10% 111,25% 88,73%
1048576 71,95% 74,31% 89,55% 89,84% 93,73%
(use 'criterium.core)
(def data
(let [sizes (take 9 (iterate #(* 4 %) 16))
r (java.util.Random. 42)
bench (fn [f]
(select-keys (benchmark (f) {}) [:mean :variance]))]
(reduce (fn [results size]
(assoc results size
(let [a (to-array (repeatedly size #(.nextLong r)))
m (persistent! (reduce #(assoc! %1 %2 %2) (transient clojure.lang.PersistentHashMap/EMPTY) a))]
(prn size)
{:assoc! (bench (fn [] (persistent! (reduce #(assoc! %1 %2 %2) (transient clojure.lang.PersistentHashMap/EMPTY) a))))
:assoc (bench (fn [] (reduce #(assoc %1 %2 %2) clojure.lang.PersistentHashMap/EMPTY a)))
:get (bench (fn [] (reduce #(get m %2) nil a)))
:dissoc (bench (fn [] (reduce dissoc m a)))
:dissoc! (bench (fn [] (persistent! (reduce dissoc! (transient m) a))))}))) {} sizes)))
kv.clj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment