Created
December 3, 2012 22:57
-
-
Save kirasystems/4198891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord Fragment [t p1 p2]) | |
(defprotocol FragmentProtocol | |
(t [fragment] "Return the type.") | |
(switch-type [fragment] "Switch type.")) | |
(deftype TypeFragment [f-type p1 p2] | |
FragmentProtocol | |
(t [this] f-type) | |
(switch-type [this] (TypeFragment. (if (= f-type :type-a) :type-a :type-b) p1 p2))) | |
(deftype TypeFragmentA [p1 p2]) | |
(deftype TypeFragmentB [p1 p2]) | |
(extend-type TypeFragmentA | |
FragmentProtocol | |
(t [this] :type-a) | |
(switch-type [this] (TypeFragmentB. (.p1 this) (.p2 this)))) | |
(extend-type TypeFragmentB | |
FragmentProtocol | |
(t [this] :type-b) | |
(switch-type [this] (TypeFragmentA. (.p1 this) (.p2 this)))) | |
#_(use 'criterium.core) | |
#_(bench | |
(loop [x (Fragment. :type-a 1 2) | |
y 20000] | |
(if-not (zero? y) | |
(case (:t x) | |
:type-a (recur (assoc x :t :type-b) (unchecked-dec y)) | |
:type-b (recur (assoc x :t :type-a) (unchecked-dec y)))))) | |
;Evaluation count : 115980 in 60 samples of 1933 calls. | |
;Execution time mean : 454.118486 us | |
;Execution time std-deviation : 21.492973 us | |
;Execution time lower quantile : 431.526125 us ( 2.5%) | |
;Execution time upper quantile : 507.327121 us (97.5%) | |
; | |
;Found 4 outliers in 60 samples (6.6667 %) | |
;low-severe 2 (3.3333 %) | |
;low-mild 2 (3.3333 %) | |
;Variance from outliers : 33.5759 % Variance is moderately inflated by outliers | |
#_(bench | |
(loop [x (TypeFragment. :type-a 1 2) | |
y 20000] | |
(if-not (zero? y) | |
(case (t x) | |
:type-a (recur (TypeFragment. :type-b (.p1 x) (.p2 x)) (unchecked-dec y)) | |
:type-b (recur (TypeFragment. :type-a (.p1 x) (.p2 x)) (unchecked-dec y)))))) | |
;Evaluation count : 242760 in 60 samples of 4046 calls. | |
;Execution time mean : 261.116716 us | |
;Execution time std-deviation : 26.578590 us | |
;Execution time lower quantile : 237.615175 us ( 2.5%) | |
;Execution time upper quantile : 316.372368 us (97.5%) | |
#_(bench | |
(loop [x (TypeFragmentA. 1 2) | |
y 20000] | |
(if-not (zero? y) | |
(recur (switch-type x) (unchecked-dec y))))) | |
;Evaluation count : 57240 in 60 samples of 954 calls. | |
;Execution time mean : 965.763854 us | |
;Execution time std-deviation : 105.626356 us | |
;Execution time lower quantile : 849.924502 us ( 2.5%) | |
;Execution time upper quantile : 1.177628 ms (97.5%) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment