Skip to content

Instantly share code, notes, and snippets.

@Hendekagon
Created August 22, 2017 10:59
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 Hendekagon/d3877ae82f9418d687c7ecfec09fe881 to your computer and use it in GitHub Desktop.
Save Hendekagon/d3877ae82f9418d687c7ecfec09fe881 to your computer and use it in GitHub Desktop.
if-vs-protocol
(use 'criterium.core)
=> nil
(defprotocol p1 (pt [this]))
=> p1
(extend-type Number p1 (pt [this] (list this)))
=> nil
(extend-type clojure.lang.PersistentList p1 (pt [this] this))
=> nil
(defn pf [x] (if (list? x) x (list x)))
=> #'user/pf
(bench (pf 9))
Evaluation count : 1471886280 in 60 samples of 24531438 calls.
Execution time mean : 37.552955 ns
Execution time std-deviation : 1.587040 ns
Execution time lower quantile : 35.809459 ns ( 2.5%)
Execution time upper quantile : 40.713527 ns (97.5%)
Overhead used : 2.154165 ns
Found 8 outliers in 60 samples (13.3333 %)
low-severe 5 (8.3333 %)
low-mild 3 (5.0000 %)
Variance from outliers : 28.6877 % Variance is moderately inflated by outliers
=> nil
(bench (pt 9))
Evaluation count : 3268418640 in 60 samples of 54473644 calls.
Execution time mean : 16.440252 ns
Execution time std-deviation : 0.745400 ns
Execution time lower quantile : 15.625599 ns ( 2.5%)
Execution time upper quantile : 17.165854 ns (97.5%)
Overhead used : 2.154165 ns
Found 5 outliers in 60 samples (8.3333 %)
low-severe 3 (5.0000 %)
low-mild 2 (3.3333 %)
Variance from outliers : 31.9258 % Variance is moderately inflated by outliers
=> nil
(bench (pt '(9)))
Evaluation count : 5459957220 in 60 samples of 90999287 calls.
Execution time mean : 9.076532 ns
Execution time std-deviation : 0.160800 ns
Execution time lower quantile : 8.799227 ns ( 2.5%)
Execution time upper quantile : 9.379562 ns (97.5%)
Overhead used : 2.154165 ns
=> nil
(bench (pf '(9)))
Evaluation count : 7413694740 in 60 samples of 123561579 calls.
Execution time mean : 6.194619 ns
Execution time std-deviation : 0.105476 ns
Execution time lower quantile : 5.969911 ns ( 2.5%)
Execution time upper quantile : 6.364845 ns (97.5%)
Overhead used : 2.154165 ns
pf list: 06ns
pf number: 38ns
pt list: 09ns
pf number: 16ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment