2010/10/18 Dmitriy S. <samborsk...@yahoo.com>: > On Oct 18, 3:07 pm, Jürgen Hötzel <juer...@hoetzel.info> wrote: >> > (defn sum [arr] >> > (loop [i (int 0) s (int 0)] >> > (if (= i *N*) s >> >> ^^^^^^^^^^^ >> >> You still doing non-primitive ops here. > > Indeed, I overlooked that. > But this was not the main cause of the trouble. > >> Also Check for areduce: >> >> (defn sum [^ints arr] >> (areduce arr i ret (int 0) >> (unchecked-add-int ret (aget arr i)))) > > This code works at the top speed. > (the time with Clojure-1.2 now is ~17 msec, same as for Java, and > with Clojure-1.3-alpha it's 67 msec) > > By comparing my code with areduce macro I've found > what was the problem -- it's a '=' operator, which I used > instead of '>='. > > Therefore this version of areduce is ~10 times slower > (in spite of being equivalent logically with the original one): > > (defmacro areduce-slow > "Reduces an expression across an array a, using an index named idx, > and return value named ret, initialized to init, setting ret to the > evaluation of expr at each step, returning ret." > {:added "1.0"} > [a idx ret init expr] > `(let [a# ~a] > (loop [~idx (int 0) ~ret ~init] > (if (= ~idx (alength a#)) ;; '=' instead of '>=' (but original
Note the difference between "=" and "==", "=" will result in a cast to the wrapped types for it's arguments. Jürgen -- 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