On May 28, 3:47 pm, Rubén Béjar <rbe...@unizar.es> wrote: > > I would thank a lot any hint, suggestion, comment, or > whatever... :-) >
Here is a version that is approx 10 times faster: http://snipt.org/Olml The code structure is basically the same but it uses integer arrays for storage, some manual inlining and lots of type casts. I'm not certain it _works_ correctly, but... :) My observations: - use the profiler. jvisualvm that comes with the sun JDK has received some much needed love recently (especially in java 1.6.0_20) and has helped me alot in profiling the code. Install an additional plugin: Sampler. It is has a much lower overhead compared to the Profiler plugin that is installed by default. Both are useful, though. - native clojure data structures (seqs, vectors, maps, etc.) are slow (compared to native Java arrays for instance). There is no going around that. Immutability and other very nice features come with a price. Dynamic languages are also, by their nature, slower than their static companions. - jvisualvm shows that in my version 40% - 50% of the time is spent in the ur-8neigh-minmax function. That time is further split into array fetches, casts to int, arithmetic (inc, dec, add, multiply, comparisons). I simply don't know how to optimise that further without changing the algorithm. On that note, the Clojure compiler and core libraries are getting better: http://snipt.org/Olmn Current Clojure 1.2.0 gives approx 10% better results. I assume (am certain, actually :)) my "improvements" can be further improved, but the code gets quite unreadable bery fast. A side note: I have been happily programing in Perl for many years now. Perl is typically 50x to 100x slower than C or Java. When people identify a performance bottleneck someone writes a version of the same thing in C. I don't see a problem with using the same approach in Clojure. You can write some quite ugly clojure (usually using mutability) that approaches Java speed or you can abstract the slow parts out and write them in Java. Hope this helps... :) -- Igor Rumiha -- 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