Why is Clojure faster than Java at this task?

2014-02-25 Thread Jonathan Barnard
I recently did a benchmark (admittedly in hindsight not a particularly good one) that involved comparison of an implementation of the same small program in Javahttps://github.com/logicchains/ArrayAccessBench/blob/master/Java3.javaand in

Re: Why is Clojure faster than Java at this task?

2014-02-25 Thread Rob Day
It looks like an improvement in clojure.lang.BigInt over java.math.BigInteger - BigInt's add() method seems to do a long + long add if it doesn't overflow (https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/BigInt.java#L142) and only fall back to BigInteger's add method (which has

Re: Why is Clojure faster than Java at this task?

2014-02-25 Thread Alex Miller
Hi Jonathan, I provided the Clojure pull request btw. I think Rob's explanation is correct. Alex On Tuesday, February 25, 2014 7:20:46 AM UTC-6, Rob Day wrote: It looks like an improvement in clojure.lang.BigInt over java.math.BigInteger - BigInt's add() method seems to do a long + long

Re: Why is Clojure faster than Java at this task?

2014-02-25 Thread Jonathan Barnard
Ah, that explanation makes sense, thank you. I imagine it would be quite cumbersome to do the same thing in Java, due to the lack of dynamic typing. On Tuesday, 25 February 2014 21:20:46 UTC+8, Rob Day wrote: It looks like an improvement in clojure.lang.BigInt over java.math.BigInteger -