Am 04.12.2008 um 20:55 schrieb PeterB:
> However, there is a heavy price to be paid for this elegance:
> 'Elapsed time: 100730.161515 msecs'
>
> Ouch! That's rather disappointing :-(
> Any suggestions for improving the performance?
In the giving thread this was already discussed. The whole
benchmark ran for me on my crappy office machine in
24 seconds and someone else tested on a more powerful
machine is 15 seconds. I'm not sure what makes the
difference. The only obvious thing is, that I used vectors
to represent the node. But I don't believe that that makes
such a difference. For the deeper details I'm too sleepy now
to look into this...
Sincerely
Meikel
PS: The code in the above mentioned thread is in no
way optimisied or something. So you can maybe do
better....
On my machine, Peter's code runs in 120 seconds.
Changing make-tree to return vectors rather than lists reduced time to
47 seconds.
Taking out the nil? test (just (if tree branch1 branch2) shaved off a
few more seconds.
Removing the pattern-matching let in check-tree (use (tree 0), (tree
1), and (tree 2)) reduced time to 33 seconds.
So these minor changes made a big difference. Maybe there's more to
do? Also, I get the impression Clojure needs to be started with the
-server flag to use all its optimizations. I haven't tried that.
I don't believe so. My impression was that the point was to be *better* than Java by: being a Lisp, being functional, and allowing safe and easy multithreading/concurrency.
That's just my impression; you'll get far more definitive answers than this.
Dave
I don't think performance is a particular criterion for the design of
this language. It's not unimportant, but the quality of the code it
engenders, especially w.r.t. to concurrency and the difficulty of
writing correct code using conventional thread-aware mechanisms,
_is_ a key design goal.
> Shouldn't the number of processors on the test machine make a big
> difference to how fast it runs? Whereas, the Java version is only
> dependent on the clock rate of the individual processors.
Only for algorithms that are both parallelizable and which have actually
been written in parallel form. There is not yet (and may never be) any
ability to automatically parallelize arbitrary algorithms or code.
> What happens if we run this benchmark on a nice 4 core core machine?
And nothing else is running? One core will be used for the thread
running this code. Another will do any I/O, though in this case there
is virtually none, and another will do GC.
This test is a sequential algorithm. I'm not familiar with the Alioth
benchmarks / shootout, but maybe there are some parallel tests in
there.
Randall Schulz
> Shouldn't the number of processors on the test machine make a big
> difference to how fast it runs? Whereas, the Java version is only
> dependent on the clock rate of the individual processors.
Replacing the "map" call with "pmap" on a 2 core machine improved my
time by about 6% (the code was already keeping both cores pretty busy).
On a 4 core machine it brought the time from 6.8 seconds down to 4.7.
On the same 4 core machine, the Java version posted by the original
poster runs in 1.3 seconds including JVM launch time.
I tried use clojure.parallel's preduce as well, but on my 4 core
machine it didn't affect the time.
--Steve