1.) use something mutable
2.) unroll all the loops (mapping is a loop)
3.) try not to coerce between seq/vec/hash-map too much.

in real world, stuff like the shootout is pretty useless, as generally
you'd reach for a better algorithm rather than implementing the
shackled, crippled, naive algorithms that the benchmark forces you to
implement.

(Not that they aren't useful to some extent, just that language
productivity and how fast you can iterate your software design in the
language is, IMO, a much better indicator of a good language than
micro benchmarking).

On Aug 10, 5:41 am, fft1976 <fft1...@gmail.com> wrote:
> I just uploaded to the group an implementation of the n-body benchmark
> in Clojure (see nbody_init.clj)
>
> http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody〈=j...
>
> My goal was to write a pure-functional version and to avoid any micro-
> optimizations. There are no type declarations and plenty of laziness
> and higher-order functions.
>
> It seems to be 100 times slower than Java (I was expecting worse) on
> my machine, putting it in the same class as Ruby, Perl and Python
> (which are imperative).
>
> The obvious things to do next here, in the order of ugliness, are:
>
> 1. switch to 3D vectors instead of arbitrary length functions
> 2. add type declarations
> 3. avoid maps
> 4. experiment with adding/removing "(vec ..."
> 5. get imperative or transient
> 6. switch to Java arrays/classes
>
> I am curious about how much more "non-idiomatic" Clojure has to become
> here for each step it takes towards Java-like performance in this
> benchmark, and whether the most optimized version will match Java in
> speed.
>
> I hope others can pick this up and implement the optimizations, or
> post their timings.
--~--~---------~--~----~------------~-------~--~----~
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