Re: Performance question (newbie)

2009-07-16 Thread Wilson MacGyver
This link reminded me of this discussion. http://www.cnn.com/2009/US/07/15/quadrillion.dollar.glitch/index.html?iref=newssearch as Rich said, unchecked is generally a bad idea. :) On Wed, Jul 15, 2009 at 10:24 PM, Rich Hickeyrichhic...@gmail.com wrote: On Jul 15, 2:22 pm, John Harrop

Performance question (newbie)

2009-07-15 Thread Dragan
Hi, I am trying to compare the performance of java loops to clojure reduce function. Noting special, Since I am just learning. Java code is something like: [code] long sum = 0; for (int i = 1; i 100; i++ ){ sum = sum + i; } [/code] while in Clojure I used: [code] (reduce + (range 1

Re: Performance question (newbie)

2009-07-15 Thread Meikel Brandmeyer
Hi, On Jul 15, 1:51 pm, Dragan draga...@gmail.com wrote: [code] long sum = 0; for (int i = 1; i 100; i++ ){     sum = sum + i;} [/code] while in Clojure I used: [code] (reduce + (range 1 i)) [/code] Comparing such a loop with reduce is a bit unfair, since the loop iteration

Re: Performance question (newbie)

2009-07-15 Thread Frantisek Sodomka
If you make it into a function and use type hints, that should help: (defn sum [n] (let [n (int n)] (loop [ret (long 0) i (int 1)] (if ( i n) (recur (+ ret i) (inc i)) ret user= (time (reduce + (range 1 100))) Elapsed time: 116.959837 msecs 4950

Re: Performance question (newbie)

2009-07-15 Thread Frantisek Sodomka
PS: Read tips on: http://clojure.org/java_interop On Jul 15, 1:51 pm, Dragan draga...@gmail.com wrote: Hi, I am trying to compare the performance of java loops to clojure reduce function. Noting special, Since I am just learning. Java code is something like: [code] long sum = 0; for

Re: Performance question (newbie)

2009-07-15 Thread Adrian Cuthbertson
It's also worth searching this group for 'performance' and checking out the discussions over the past few months. There've been lots of queries about many different aspects of performance and some really good advice dispensed. - Adrian. On Wed, Jul 15, 2009 at 3:39 PM, Frantisek

Re: Performance question (newbie)

2009-07-15 Thread Aaron Cohen
Another note is that these kind of micro-benchmarks are a little difficult to do correctly in most modern VMs, including Hotspot. In particular, the kind of tight loop you're doing there where the result isn't used can sometimes be optimized away by the JIT to go infinitely fast. A pretty good

Re: Performance question (newbie)

2009-07-15 Thread B Smith-Mannschott
On Wed, Jul 15, 2009 at 13:51, Dragandraga...@gmail.com wrote: Hi, I am trying to compare the performance of java loops to clojure reduce function. Noting special, Since I am just learning. Java code is something like: [code] long sum = 0; for (int i = 1; i 100; i++ ){    sum = sum

Re: Performance question (newbie)

2009-07-15 Thread John Harrop
On Wed, Jul 15, 2009 at 11:39 AM, B Smith-Mannschott bsmith.o...@gmail.comwrote: An explicit loop with some type hints is faster, though likely not as fast as Java: (defn sum-of-range-4 [range-limit] (loop [i (int 1) s (long 0)] (if ( i range-limit) (recur (inc i) (+ s i))

Re: Performance question (newbie)

2009-07-15 Thread Dragan
Guys, thanks very much for the fast responses. Of course, this is an unscientific and totally ad-hock benchmark. I am just *learning* Clojure and functional programming and I wanted to get some feeling of how fast Clojure is comparing to java when equivalent idioms are used . Of course, loop and

Re: Performance question (newbie)

2009-07-15 Thread Rich Hickey
On Jul 15, 2:22 pm, John Harrop jharrop...@gmail.com wrote: On Wed, Jul 15, 2009 at 11:39 AM, B Smith-Mannschott bsmith.o...@gmail.comwrote: An explicit loop with some type hints is faster, though likely not as fast as Java: (defn sum-of-range-4 [range-limit]  (loop [i (int 1) s