On Aug 10, 5:15 pm, Andy Fingerhut <andy_finger...@alum.wustl.edu>
wrote:
> OK, I've got a new Clojure program for the n-body benchmark, and it is
> significantly faster than my previous one -- down from 138 x Java run
> time, to 37 x Java run time.  Still room for improvement somewhere
> there, I'm sure, including perhaps using Java arrays instead of
> Clojure vectors.
>
> http://github.com/jafingerhut/clojure-benchmarks/blob/2423c5ba7bcded3...
>
> The main changes from the slower version are:
>
> + make separate vectors for each "attribute" of a body in motion, i.e.
> a separate vector of positions, a vector of velocities, etc., instead
> of using maps.
> + Use loop/recur almost everywhere it makes sense.  I still have a few
> map calls in the function 'energy' and the functions it calls, and
> maybe in the init code, but that is only done twice and once during
> the whole execution, versus advance which is called 50,000,000 times
> in the long version of the benchmark.
> + It uses the new transient/assoc!/conj!/persistent! functions for
> Clojure vectors, so you need a pretty new copy of Clojure if you want
> to run it yourself.

I don't have the CVS version with transients, so I can't test your
version. This new version I just uploaded (nbody_v2.clj in the group
vault) is 55x slower than Java in my tests, which should make it 1.5x
slower than yours, but it uses no macros, transients, type hints,
struct-maps (it uses maps), Java arrays or mutation.

I tried struct-maps. They made things worse. Type hints do make it
faster, but only 1.3-1.4 times (perhaps I didn't add them well), so I
decided that they are not worthwhile at this point.

I'll write a Java-in-Clojure version of this in a week or two, if
nobody does it first.
--~--~---------~--~----~------------~-------~--~----~
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