Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(def a1 (array 1 2 3))
(def a2 (array 4 5 6))
(dotimes [_ 5]
(time
(dotimes [_ 1000000]
(let [x1 (aget a1 0)
y1 (aget a1 1)
z1 (aget a1 2)
x2 (aget a2 0)
y2 (aget a2 1)
z2 (aget a2 2)]
(array (+ x1 x2) (+ y1 y2) (+ z1 x2))))))
(deftype Vec3d [x y z])
(def v1 (Vec3d. 1 2 3))
(def v2 (Vec3d. 4 5 6))
(dotimes [_ 5]
(time
(dotimes [_ 1000000]
(let [x1 (.-x v1)
y1 (.-y v1)
z1 (.-z v1)
x2 (.-x v2)
y2 (.-y v2)
z2 (.-z v2)]
(Vec3d. (+ x1 x2) (+ y1 y2) (+ z1 x2))))))
;; Testing with V8
;; "Elapsed time: 17 msecs"
;; "Elapsed time: 11 msecs"
;; Testing with SpiderMonkey
;; "Elapsed time: 676 msecs"
;; "Elapsed time: 1475 msecs"
;; Testing with JavaScriptCore
;; "Elapsed time: 108 msecs"
;; "Elapsed time: 87 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.