Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikera/72a739c84dd52fa3b6d6 to your computer and use it in GitHub Desktop.
Save mikera/72a739c84dd52fa3b6d6 to your computer and use it in GitHub Desktop.
Benchmarking for tuple performance
;; *clojure-version*
;; (require '[taoensso.encore :as encore])
(let [v [1 2 3 4]
x 1
y 2
z 3]
(encore/qbench ; Returns fastest of 3 sets of lap times for each form, in msecs
1000000 ; Number of laps
(conj v 5) ; 82.06 -> 82.53 ; 1.0x
(assoc v 1 "boo") ; 110.96 -> 94.83 ; 1.2x
(subvec v 1 3) ; 80.59 -> 79.92 ; 1.0x
(assoc {} :v1 v :v2 v :v3 v) ; 364.08 -> 453.77 ; 0.8x
[x y z] ; 112.33 -> 118.52 ; 0.9x
(let [[x y z] v]) ; 234.74 -> 190.26 ; 1.2x
(peek v) ; 67.59 -> 66.81 ; 1.0x
(pop v) ; 84.09 -> 70.72 ; 1.2x
(seq v) ; 84.83 -> 87.03 ; 1.0x
(reduce (fn [acc in]) nil v) ; 215.07 -> 116.22 ; 1.9x ; Faster
(mapv inc v) ; 404.19 -> 192.46 ; 2.1x ; Faster
(into [0] v) ; 585.51 -> 337.02 ; 1.7x ; Faster
(count v) ; 41.05 -> 42.77 ; 1.0x
(seq v) ; 84.67 -> 85.12 ; 1.0x
(rseq v) ; 70.44 -> 70.31 ; 1.0x
[[[x y z] y z] y z] ; 278.53 -> 278.72 ; 1.0x
(hash [[[x y z] y z] y z]) ; 648.10 -> 575.27 ; 1.1x
(hash [x y z]) ; 271.99 -> 266.74 ; 1.0x
(= v [1 2 3 "foo"]) ; 221.30 -> 90.27 ; 2.5x ; Faster
))
;; Clojure 1.8.0-alpha2 (current master)
[82.06 110.96 80.59 364.08 112.33 234.74 67.59 84.09 84.83 215.07 404.19 583.51 41.05 84.67 70.44 278.53 648.1 271.99 221.3]
;; Clojure 1.8.0-temp (mikera's clj-1517 branch using Zach Tellman's unrolled Tuples)
;; https://github.com/mikera/clojure/commit/7b9cbb804997c75c0aeeffa1e639fa0f2e0d1bda
[82.53 94.83 79.92 453.77 118.52 190.26 66.81 70.72 87.03 116.22 192.46 337.02 42.77 85.12 70.31 278.72 575.27 266.74 90.27]
;; Ratios
[0.994 1.170 1.008 0.802 0.948 1.234 1.012 1.189 0.975 1.851 2.100 1.731 0.960 0.995 1.002 0.999 1.127 1.020 2.452]
;; Notes:
;; 1. All tests run at Counterclockwise REPL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment