Consider using core.matrix with vectorz-clj for operations on large numerical arrays / vectors of doubles. It is a *lot* faster than using Clojure vectors for this kind of scenario, plus it has a lot of helpful array operations already defined.
(use 'clojure.core.matrix) (def v (array :vectorz (range 1280000))) (time (emax v)) => 1279999.0 "Elapsed time: 1.179533 msecs" On Wednesday, 10 June 2015 21:07:09 UTC+1, Ritchie Cai wrote: > > I'm working on a java array of double with 1280000 elements. I need the > max and min values of the array. So I initially tried areduce and loop, > both gives runs around 20 seconds. But when try (apply max (vec array)) I > get result under 90 ms. > Can anyone explain why there is such a big difference? > Also if want to iterate large java array like this to do some other > operations, e.g. convolution, what's the best way to go? Is there another > fast way to iterate through array or do I need to convert array into vector? > > Thanks > Ritchie > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.