[erlang-questions] N-Queens

Serge Aleynikov serge@REDACTED
Wed Jan 3 18:08:15 CET 2007


Greetings!

I wrote an N-Queen problem solver in C/C++/OCaml/Erlang for conducting a 
benchmarking exercise.  Here are results:

$ wc -l nqueens.{c,cpp,ml,erl}
   93 nqueens.c
  109 nqueens.cpp
   61 nqueens.ml
   61 nqueens.erl

On my host timing is as follows:

$ make run   # 8 queens, 1000 times
# Program               Time
./queens_c:             0.96
./queens_cpp:           1.16
./queens_ml:            0.77     # OCaml natively compiled
./queens_ml.bcode:      22.55    # OCaml bytecode compiled
nqueens.beam:           8.56

Note that Erlang code is natively compiled.  Without the native flag it 
gives about the same time as queens_ml.bcode.

If we use optimization (-O3 for C/C++ and -unsafe for OCaml) the timing 
picture is slightly different.

I am curious if anyone can suggest any improvement to nqueens.erl 
(preserving the algorithm) that would increase its performance (other 
that parallelization).

Regards,

Serge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nqueens.tar.gz
Type: application/x-gzip
Size: 3321 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070103/6337d439/attachment.bin>


More information about the erlang-questions mailing list