It is safe to assume that Python uses the GMP library for its infinite
precision math, no? This could be a big part of the explanation as, if
the language shootouts are to be believed, BigInteger and BigDecimal
have inferior performance when compared to what can be achieved with
GMP.

For problems that can be solved within the constraints of 32 bits,
number boxing would be a likely candidate perfomance drain; the
function interfaces speak in Objects and therefor any number that
wishes to cross a function boundary, either as a parameter or as a
return value, must be a subclass of Object and that means boxing of
primitives, which in turn means object allocation and GC.

Also, the server (HotSpot) VM currently requires 10.000 calls of a
method before it will consider JIT'ing it.

On Mon, Feb 2, 2009 at 4:35 PM, Gregory Petrosyan
<gregory.petros...@gmail.com> wrote:
>
> Hello everybody,
>
> Althrough I am new to Clojure, I like it a lot. Because it is
> advertised as native JVM language, I expected it to demostrate decent
> performance in simple numeric tests, so I decided to compare it to
> Python.
>
> Clojure rev. 1173:
> user=> (defn fac [#^Integer n] (reduce * (range 1 (+ 1 n))))
> #'user/fac
> user=> (time (reduce + (map fac (range 1000))))
> "Elapsed time: 944.798019 msecs"
>
> Python 3.0:
>>>> import timeit
>>>> t=timeit.Timer('sum(fac(n) for n in range(1000))', 'from functools import 
>>>> reduce; from operator import mul; fac = lambda n: reduce(mul, range(1, 
>>>> n+1), 1)')
>>>> t.timeit(10)/10
> 0.35052159800038679
>
> This is XP SP2 on Core2 Duo, with 3Gb of RAM.
>
> As you can see, Python is almost 3 times faster on this
> microbenchmark! Can anybody explain this to me? (No flame wars,
> please, I am really interested in why the things are as they are, is
> it considered ok or not, and what can be done to make Clojure faster
> on similar tests).
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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