-
-
Save mseddon/c40767dc2042b0d18ab8a69484c75116 to your computer and use it in GitHub Desktop.
variadic performance hit
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
(deftype Vec3 [x y z]) | |
(defn vec3+ | |
[a b] | |
(Vec3. (+ (.-x a) (.-x b)) | |
(+ (.-y a) (.-y b)) | |
(+ (.-z a) (.-z b)))) | |
(defn vec3+v | |
([a b] | |
(Vec3. (+ (.-x a) (.-x b)) | |
(+ (.-y a) (.-y b)) | |
(+ (.-z a) (.-z b)))) | |
([a b c] | |
(Vec3. (+ (.-x a) (.-x b) (.-x c)) | |
(+ (.-y a) (.-y b) (.-y c)) | |
(+ (.-z a) (.-z b) (.-z c))))) | |
(defn bench[] ;; "Elapsed time: 7.300000 msecs" | |
(time (dotimes [x 1000000] | |
(vec3+ (Vec3. 1 2 3) | |
(Vec3. 4 5 6))))) | |
(defn bench-v[] ;; "Elapsed time: 105.700000 msecs" | |
(time (dotimes [x 1000000] | |
(vec3+v (Vec3. 1 2 3) | |
(Vec3. 4 5 6))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment