I've been playing around with a generalised version of the N-Queens problem 
that handles other chess pieces. I have a Scala implementation that uses an 
eager depth-first search. Given enough RAM (around 12G - it's very memory 
hungry!) it can solve a 6x9 board with 6 pieces in around 2.5 minutes on my 
MacBook Pro.

I then created a Clojure version of the same algorithm with the intention of 
(eventually) using laziness to avoid the memory issue. However, the performance 
of the Clojure version is several orders of magnitude worse than the Scala 
version (I've left it running overnight on the problem that the Scala version 
solves in 2.5 minutes and it still hasn't completed).

I'm struggling to see why the performance of the Clojure version is so much 
worse than the Scala. Profiling in YourKit suggests that it's spending 99% of 
its time in PersistentHashSet.cons, but I'm at a loss to explain why. I would 
be grateful for any insight.

The code for the two different versions is on GitHub:

https://github.com/paulbutcher/chess-scala
https://github.com/paulbutcher/chess-clojure

Notes:

- I know that an exhaustive depth-first search isn't a great way to tackle this 
problem. But I'd like to understand why I see such a dramatic difference 
between the performance of the Scala and Clojure versions.

- I believe that I've implemented the same algorithm in both Scala and Clojure 
- certainly they both generate the same results for small problems (there are 
3x3 and 4x4 problems commented out in the source). But clearly I can't rule out 
the possibility that I've made a mistake in the Clojure implementation. If 
anyone can spot my stupid mistake, I'd greatly appreciate it.

Thanks in advance for any insight that anyone can offer.

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

-- 
-- 
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.

Reply via email to