From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.5 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST,MSGID_FROM_MTA_HEADER,SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E70E0BC0B for ; Thu, 28 Dec 2006 17:04:00 +0100 (CET) Received: from bay0-omc2-s37.bay0.hotmail.com (bay0-omc2-s37.bay0.hotmail.com [65.54.246.173]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBSG3x1o004703 for ; Thu, 28 Dec 2006 17:04:00 +0100 Received: from hotmail.com ([65.54.169.36]) by bay0-omc2-s37.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Thu, 28 Dec 2006 08:03:59 -0800 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 28 Dec 2006 08:03:58 -0800 Message-ID: Received: from 65.54.169.200 by by114fd.bay114.hotmail.msn.com with HTTP; Thu, 28 Dec 2006 16:03:55 GMT X-Originating-IP: [141.228.106.136] X-Originating-Email: [oversby@hotmail.com] X-Sender: oversby@hotmail.com In-Reply-To: <15946.213.30.139.86.1167315231.squirrel@webmail.nerim.net> From: "Ian Oversby" To: oandrieu@nerim.net Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question on writing efficient Ocaml. Date: Thu, 28 Dec 2006 16:03:55 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 28 Dec 2006 16:03:58.0796 (UTC) FILETIME=[C8A4E0C0:01C72A99] X-j-chkmail-Score: MSGID : 4593EAEF.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 4593EAEF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 unneeded:01 unboxing:01 solver:01 ocamlopt:01 -noassert:01 -unsafe:01 compiler:01 caml-list:01 caml:02 caml:02 inefficient:02 bounds:02 constructs:02 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