The performance of array iteration in cljs is not good compared vs. native
iteration on js array.
For example, I would like to sum all the members of on array.
I have tried (apply + arr) and (doseq ...). See below.
Is there a way to improve my code?
(def arr (range 20480))
(set! js/arr (clj->js arr))
(js/eval "function sum(arr) {
var total = 0,
i;
for (i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}")
(defn my-sum[a]
(def res 0)
(doseq [x a]
(set! res (+ res x )))
res)
(time (js/sum js/arr)) ; less than 1 msec
(time (apply + arr)); around 10 msec
(time (my-sum arr)); around 10 msec
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.