What's puzzle me is that past at certain number (10 millions), clojure
chocks and throw a «java.lang.OutOfMemoryError: Java heap space»,
continue for a while and stop before completing the sequence.

The JVM puts a limit on the amount of memory that will be allocated. Try adding -Xmx512m to your java invocation, and you'll get much further. Also make sure you're running with -server.


It is also 10x slower compared to python, that manage to complete it
successfully.

You might have to run a method tens of thousands of times before the Hotspot JIT will optimize an invocation.

Furthermore, (filter even? (range 10000000)) in the REPL will try to print the sequence. That's no good.

To attempt to time this fairly, I tried


user=> (time (count (filter even? (range 10000000))))
"Elapsed time: 1690.235 msecs"
5000000
user=> (time (count (filter even? (range 10000000))))
"Elapsed time: 1127.633 msecs"
5000000


It stabilizes quite quickly.


Python:


>>> import time
>>> def tryout():
...   t1 = time.time()
...   print len(filter(evenp,range(10000000)))
...   t2 = time.time()
...   print t2 - t1
...
>>> tryout()
5000000
3.80207896233
>>> tryout()
5000000
4.21358513832

In short: Clojure is about 4x faster than Python on this trivial example.

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