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 Hickey wrote: > > > > On Jul 15, 2:22 pm, John Harrop wrote: >> On Wed, Jul

Re: Performance question (newbie)

2009-07-15 Thread Rich Hickey
On Jul 15, 2:22 pm, John Harrop wrote: > On Wed, Jul 15, 2009 at 11:39 AM, B Smith-Mannschott > wrote: > > > 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-l

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 John Harrop
On Wed, Jul 15, 2009 at 11:39 AM, B Smith-Mannschott wrote: > 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)) > s))) > > This

Re: Performance question (newbie)

2009-07-15 Thread B Smith-Mannschott
On Wed, Jul 15, 2009 at 13:51, Dragan 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 + i; >

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 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 Sodomka wrote: >

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 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;

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 u

Re: Performance question (newbie)

2009-07-15 Thread Meikel Brandmeyer
Hi, On Jul 15, 1:51 pm, Dragan 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 heavily d

Re: performance question

2008-12-14 Thread Justin Henzie
Nice code chouser, always nice to see a succinct functional example. On Dec 13, 10:15 am, Chouser wrote: > On Sat, Dec 13, 2008 at 10:41 AM, Dmitri wrote: > > > I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/ > > it reads stdin and counts the occurrences of words, however

Re: performance question

2008-12-13 Thread Dmitri
thanks for pointing this out, and I absolutely appreciate the example. I'm still new to functional approach and I always like to see how things are done properly. On Dec 13, 1:15 pm, Chouser wrote: > On Sat, Dec 13, 2008 at 10:41 AM, Dmitri wrote: > > > I wrote a simple word counter described h

Re: performance question

2008-12-13 Thread Dmitri
To give an example, I tried running through the Iliad from project gutenberg, it's roughly 1MB of text http://www.gutenberg.org/files/6130/6130.txt and the program takes ~4600 ms to run, if I comment out printing of results it runs in ~3700 ms. By contrast a java version runs in ~560ms. Now, obv

Re: performance question

2008-12-13 Thread Chouser
On Sat, Dec 13, 2008 at 10:41 AM, Dmitri wrote: > > I wrote a simple word counter described here http://ptrace.fefe.de/wp/ > it reads stdin and counts the occurrences of words, however I notice > that it runs significantly slower than the java version in the link. There are several differences t

Re: performance question

2008-12-13 Thread Dmitri
I added the time call later on to find what was taking up the cycles, I also checked the reverse, it's impact is minimal, the print-words part of the program runs fast, but the read-words takes the majority of the time. On Dec 13, 12:38 pm, Jeremy Dunck wrote: > On Dec 13, 9:41 am, Dmitri wrote

Re: performance question

2008-12-13 Thread Jeremy Dunck
On Dec 13, 9:41 am, Dmitri wrote: ... > The slowdown seems to occur in the inc-count > function, where it "updates" the map using the assoc. Is this not a > proper way to approach this in clojure? (recur (time (inc-count words head)) tail You're pretty tightly looping here-- a

Re: performance question

2008-12-13 Thread Michel Salim
On Dec 13, 10:41 am, Dmitri wrote: > I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/ > it reads stdin and counts the occurrences of words, however I notice > that it runs significantly slower than the java version in the link. > > I was wondering why there is such a dramatic