Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Comparing performance of Clojure's protocols, records and maps for fn dispatch
(deftype Qp [] Q (q [this x] x))
=> user.Qp
(def Qm {:q (fn [x] x)})
=> #'user/Qm
(def Qp1 (Qp.))
=> #'user/Qp1
(c/quick-bench (q Qp1 7))
Evaluation count : 150426264 in 6 samples of 25071044 calls.
Execution time mean : 2.073561 ns
Execution time std-deviation : 0.274594 ns
Execution time lower quantile : 1.798391 ns ( 2.5%)
Execution time upper quantile : 2.456995 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench (q Qp1 7))
Evaluation count : 79931094 in 6 samples of 13321849 calls.
Execution time mean : 5.689320 ns
Execution time std-deviation : 0.231769 ns
Execution time lower quantile : 5.396984 ns ( 2.5%)
Execution time upper quantile : 5.893860 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench ((:q Qm) 7))
Evaluation count : 39013842 in 6 samples of 6502307 calls.
Execution time mean : 13.782063 ns
Execution time std-deviation : 0.453444 ns
Execution time lower quantile : 13.272050 ns ( 2.5%)
Execution time upper quantile : 14.386597 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench ((:q Qm) 7))
Evaluation count : 39673668 in 6 samples of 6612278 calls.
Execution time mean : 13.383501 ns
Execution time std-deviation : 0.595046 ns
Execution time lower quantile : 12.779120 ns ( 2.5%)
Execution time upper quantile : 14.047624 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench (q Qp1 7))
Evaluation count : 78018276 in 6 samples of 13003046 calls.
Execution time mean : 5.799961 ns
Execution time std-deviation : 0.235095 ns
Execution time lower quantile : 5.557335 ns ( 2.5%)
Execution time upper quantile : 6.150434 ns (97.5%)
Overhead used : 2.177397 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 13.8889 % Variance is moderately inflated by outliers
=> nil
(defrecord Qr [q])
=> user.Qr
(def qr1 (Qr. (fn [x] x)))
=> #'user/qr1
(c/quick-bench ((:q qr1) 7))
Evaluation count : 60229422 in 6 samples of 10038237 calls.
Execution time mean : 7.968124 ns
Execution time std-deviation : 0.344445 ns
Execution time lower quantile : 7.378712 ns ( 2.5%)
Execution time upper quantile : 8.329300 ns (97.5%)
Overhead used : 2.177397 ns
Found 1 outliers in 6 samples (16.6667 %)
low-severe 1 (16.6667 %)
Variance from outliers : 13.8889 % Variance is moderately inflated by outliers
=> nil
(c/quick-bench ((:q qr1) 7))
Evaluation count : 58318404 in 6 samples of 9719734 calls.
Execution time mean : 8.079567 ns
Execution time std-deviation : 0.273543 ns
Execution time lower quantile : 7.629557 ns ( 2.5%)
Execution time upper quantile : 8.325156 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench (q Qp1 7))
Evaluation count : 77435766 in 6 samples of 12905961 calls.
Execution time mean : 5.672079 ns
Execution time std-deviation : 0.354724 ns
Execution time lower quantile : 5.173754 ns ( 2.5%)
Execution time upper quantile : 6.006631 ns (97.5%)
Overhead used : 2.177397 ns
=> nil
(c/quick-bench ((:q Qm) 7))
Evaluation count : 41172372 in 6 samples of 6862062 calls.
Execution time mean : 13.551723 ns
Execution time std-deviation : 0.414482 ns
Execution time lower quantile : 13.060801 ns ( 2.5%)
Execution time upper quantile : 13.970792 ns (97.5%)
Overhead used : 2.177397 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.