I'm really sorry for coming back to this but even after everything we
learned I'm still not able to get performance equal to java in a simple
factorial benchmark. I'd like to think that I'm doing all the correct
things to keep the comparison fair...observe this:

benchmarks.core=> (crit/bench (jf! 50))
WARNING: Final GC required 2.3432463351555 % of runtime
Evaluation count : 311580 in 60 samples of 5193 calls.
             Execution time mean : 196.444969 µs
    Execution time std-deviation : 10.637274 µs
   Execution time lower quantile : 194.356268 µs ( 2.5%)
   Execution time upper quantile : 197.042127 µs (97.5%)
                   Overhead used : 258.723396 ns

Found 9 outliers in 60 samples (15.0000 %)
        low-severe       2 (3.3333 %)
        low-mild         7 (11.6667 %)
 Variance from outliers : 40.1247 % Variance is moderately inflated by
outliers nil

now java:

benchmarks.core=> (crit/bench (.factorial ^Benchmarks (Benchmarks.) 50))
WARNING: Final GC required 2.656271755497413 % of runtime
Evaluation count : 562260 in 60 samples of 9371 calls.
             Execution time mean : 107.148989 µs
    Execution time std-deviation : 1.650542 µs
   Execution time lower quantile : 106.504235 µs ( 2.5%)
   Execution time upper quantile : 108.934066 µs (97.5%)
                   Overhead used : 258.723396 ns

Found 5 outliers in 60 samples (8.3333 %)
        low-severe       1 (1.6667 %)
        low-mild         4 (6.6667 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by
outliers

can you spot any differences with this code that would justify needing
almost twice as much time?

(defn jf! "Calculate factorial of n as fast as Java without overflowing." [n]
 (loop [i (int n)
           ret 1N]
 (if (== 1 i) ret
 (recur (dec i) (* ret i)))))

now java:

  public BigInteger factorial(final int n){
    BigInteger res = BigInteger.valueOf(1L); //build upresult
           for (int i = n; i > 1; i--)
               res = res.multiply(BigInteger.valueOf(i));
          return res;
   }

I know this is getting ridiculous but I'm preparing a presentation and
I was sort of counting on this example...Of course, it goes without
saying that I'm using unchecked-math and :jvm-opts ^replace[] .


am I doing something wrong?

thanks for your time

Jim


On Fri, 14 Jun 2013 00:11:52 -0700 (PDT)
Jason Wolfe <ja...@w01fe.com> wrote:

Thanks for your response.  I attempted to answer this in my
clarification, but our goal is to attack this 'general advice' and
make it possible to get the same speed for array handling in
natural-seeming Clojure without writing Java.  In particular, we want
to create macros that make it easy to achieve maximum performance by
putting *your code* for manipulating array elements in the middle of
an optimized loop, and this can't be done easily at the library level
(as far as I can see) by dropping to Java, since in Java your code
would always have to be wrapped in a method invocation with
corresponding performance implications.

Our previous version of this library (developed for Clojure 1.2,
IIRC) was able to get within 0-30% or so of raw Java speed while
providing a clean Clojure interface, and we're trying to get back to
this point with Clojure 1.5 so we can release it as open-source for
everyone to use.

-Jason

On Friday, June 14, 2013 12:04:12 AM UTC-7, Glen Mailer wrote:
>
> This doesn't really answer your question directly, but is there a
> reason you need to keep this in clojure, or are you just aiming to
> establish why this is happening?
>
> My understanding was that for performance critical code the general
> advice is to drop down to raw java?
>
> Glen
>
>


--
--
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/groups/opt_out.


Reply via email to