On 29.06.2009, at 20:41, fft1976 wrote:

> It's been argued by some that Clojure is as fast as Java, because at
> worst, you can implement your bottlenecks in Java. I have a problem
> with this argument, because the data structures that your Java has to
> work with are still (wasteful) Clojure ones.
>
> For example, a matrix data structure in Clojure could be based on Seqs
> (or Seqs of Seqs) of dynamically typed elements. There is overhead
> associated with this dynamic typing and mutation of the elements.

Choosing the right data structures is at least as important as  
choosing the right language. If you have to deal with 10 MB of  
floats, the right data structure (in the JVM world) is the Java  
array, no matter whether your code is written in Clojure or in Java.

> When you discover that some procedure working on such data structure
> is slow, you can reimplement it in Java, but do you think it could
> compete with Java working on native statically typed arrays of floats?

What is particularly nice about Clojure is that in most situations  
you don't need to switch to Java for speed. You can optimize your  
code by adding type hints and switching to low-level data structures  
(unboxed ints and floats, arrays, ...) and get performance equal to  
Java. The main limitation is that unboxed numbers can't be used at  
the interface between two functions.

Low-level Clojure code is better than Java code because you still  
have the full macro system. Instead of hand-coding, you can often  
write a few macros that generate the low-level code for you.

> I would be curious to know if anyone is using Clojure for CPU-
> intensive work where performance really counts.

Not yet, but I plan to experiment with it in the near future.

Konrad.


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