On Friday, March 1, 2013 5:35:16 AM UTC+1, yizhen wei wrote: > I just start learning clojure recently. > > So I was looking for some performance related post on the internet, and > found some optimization tips, "fast" clojure code and so on. Which lead to > the question above. > It seems like most of the time we have to write longer, more java-like > code (which I found less readable to java equivalence) to catch up java's > speed. > Is that just the trade-off we need to make in order to type less character? > > What is the difference in performance between "true" clojure (without > using type hint or other java stuffs) and java? >
First of all, it happens that in most any real-life project only about 1% of code needs aggressive optimization. Performance is usually limited by the delays in communication with external subsystems such as the filesystem, database, and so on. But, once we limit our discussion to performance-critical code, this is the picture: without type hints, JVM Clojure's performance is sheer disaster: a reflective call is ~1000 times slower than a type-hinted one. After type-hinting (it's relatively easy due to compiler warnings) you'll still find it a challenge to rise above 10% of idiomatic Java performance with idiomatic Clojure. In the face of type hints the code still keeps its original, idiomatic structure, so it really isn't a big deal if you need to type-hint 1% of your code. However, if you find that the resulting performance still doesn't cut it, you'll have to completely rewrite it in the "optimized" idiom, which is basically Java without reassignable local vars and with the unwieldy *loop-recur *construct. With each release of Clojure new optimizations come around, so you must continually track the goings-on. Take good note of what *reduce* can do for you; it's the most general, "low-level" higher-order function, which has been quite aggressively optimized and special-cased. Read about *recuders<http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html> * as well. In the end I'd like to add that Clojure was the easiest language for me to learn and writing code in it is, as many will testify, a *joy* I haven't experienced with any other language, Common Lisp included. My company has a whole portfolio of mission-critical enterprise systems done in 100% Clojure, with blazing performance. The performance mainly results from Clojure allowing us to keep it simple and obvious. Java's raw performance doesn't mean a thing when you do your project in something like Enterprise Java Beans. -Marko -- -- 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.