Created
December 14, 2010 08:37
-
-
Save raek/740151 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
(definterface IMixedAddition | |
(plus [^Long x ^Double y]) | |
(plus [^Double x ^Long y])) | |
(deftype MixedAdditionImpl [] | |
IMixedAddition | |
(plus [this ^Long x ^Double y] | |
"foo") | |
(plus [this ^Double x ^Long y] | |
"bar")) | |
(def dummy (MixedAdditionImpl.)) | |
(time (dotimes [_ 1e6] | |
(.plus dummy (long 1) (double 1)))) | |
;; Reflection warning, NO_SOURCE_FILE:1 - call to plus can't be resolved. | |
;; "Elapsed time: 1560.983138 msecs" | |
(defmulti multiplus (fn [l r] [(type l) (type r)])) | |
(defmethod multiplus [Long Double] | |
[l r] | |
"foo") | |
(defmethod multiplus [Double Long] | |
[l r] | |
"bar") | |
(time (dotimes [_ 1e6] | |
(multiplus (long 1) (double 1)))) | |
;; "Elapsed time: 781.060692 msecs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment