Browse thread
Re: [Caml-list] Question on writing efficient Ocaml.
- Ian Oversby
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-12-28 (16:04) |
From: | Ian Oversby <oversby@h...> |
Subject: | Re: [Caml-list] Question on writing efficient Ocaml. |
Hi Olivier, Thanks for the response. > > Hi, > > > I've written some Ocaml code to solve the problem of placing 8 queens on >a > > board so that none of them attack each-other. I've also written a C++ > > equivalent which is running much more quickly than the Ocaml. I assume > > I've > > made some basic errors with the Ocaml - does anyone have any suggestions > > as > > to what? > >there is room for improvement: for instance the type definitions of posn >and board at the very beginning of the program introduce some unneeded >boxing of values. Does this mean that unboxing is inefficient in OCaml? I've written an alternative version of the C++ that returns NULL instead of out of bound values which was close to the same speed so it would be a little disappointing if I couldn't achieve something similar in OCaml with Some / None. Let me try to convert the OCaml to use out of bounds board values instead to see if that solves the speed problem. >You might want to compare with this solution of the queens problem in >ocaml: > http://caml.inria.fr/pub/old_caml_site/Examples/oc/basics/queens.ml I've written a queens solver along the same lines which is much faster than my other example as it makes many fewer calls and constructs fewer (and simpler) boards. > > I compiled the Ocaml with the following command: > > > > ocamlopt -noassert -unsafe -ccopt -O3 -ccopt -fomit-frame-pointer q.ml >-o > > q.exe > >the "-ccopt -O3 -ccopt -fomit-frame-pointer" are completely pointless: the >ocaml compiler does not generate C code, it generates asm ! Well, that is certainly good to know. Thanks very much :) >-- > Olivier Ian _________________________________________________________________ MSN Hotmail is evolving – check out the new Windows Live Mail http://ideas.live.com