Skip to content

Instantly share code, notes, and snippets.

@mseddon

mseddon/ow.cljc Secret

Last active November 21, 2018 15:29
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 mseddon/c40767dc2042b0d18ab8a69484c75116 to your computer and use it in GitHub Desktop.
Save mseddon/c40767dc2042b0d18ab8a69484c75116 to your computer and use it in GitHub Desktop.
variadic performance hit
(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