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 presentation about this from JavaONE can be found here:
http://www.azulsystems.com/events/javaone_2009/session/2009_J1_Benchmark.pdf
-- Aaron


On Wed, Jul 15, 2009 at 10:01 AM, Adrian Cuthbertson <
adrian.cuthbert...@gmail.com> wrote:

>
> 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<fsodo...@gmail.com>
> wrote:
> >
> > 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 (int i = 1; i < 1000000; i++ ){
> >>     sum = sum + i;}
> >>
> >> [/code]
> >>
> >> while in Clojure I used:
> >>
> >> [code]
> >> (reduce + (range 1 i))
> >> [/code]
> >>
> >> Execution time for the Java version is 7 ms, while Clojure needs 60 -
> >> 160 ms.
> >> Now, that is expected, since Clojure runs in REPL.
> >> Next, I tried the gen-class of the Clojure, and called that Class from
> >> Java (so no REPL involved), but the code haven't speed up at all!
> >> Am I missing something or such 10x performance penalty is usual for
> >> such operations?
> > >
> >
>
> >
>

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

Reply via email to