From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9E8FDBC84 for ; Thu, 24 Mar 2005 23:42:10 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2OMgAjU029025 for ; Thu, 24 Mar 2005 23:42:10 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA20113 for ; Thu, 24 Mar 2005 23:42:09 +0100 (MET) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2OMg8q6011400 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 24 Mar 2005 23:42:09 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DEb1Q-0005nK-2R for caml-list@inria.fr; Thu, 24 Mar 2005 23:41:48 +0100 Received: from 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk ([80.165.187.141]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Mar 2005 23:41:48 +0100 Received: from spam by 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 24 Mar 2005 23:41:48 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Bardur Arantsson Subject: Re: Pervasives.compare output type Date: Thu, 24 Mar 2005 23:41:49 +0100 Message-ID: References: <42430B3B.60408@barettadeit.com> <20050324194115.GB9518@furbychan.cocan.org> <87acosu5c9.fsf@qrnik.zagroda> <87d5ton11t.fsf@qrnik.zagroda> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 0x50a5bb8d.odnxx9.adsl-dhcp.tele.dk User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050323) X-Accept-Language: en-us, en In-Reply-To: <87d5ton11t.fsf@qrnik.zagroda> Sender: news X-Gmane-MailScanner: Found to be clean X-Gmane-MailScanner: Found to be clean X-MailScanner-From: gclci-caml-list@m.gmane.org X-MailScanner-To: caml-list@inria.fr X-Miltered: at nez-perce with ID 42434242.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42434241.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; pervasives:01 pervasives:01 integers:01 subtraction:01 integers:01 ocaml:01 ocaml:01 subtraction:01 recursion:01 enumeration:01 enumeration:01 val:01 branching:01 higher-order:01 cheers:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Marcin 'Qrczak' Kowalczyk wrote: > Bardur Arantsson writes: > > >>>>Wouldn't it be for speed? You could define Pervasives.compare over >>>>integers just as a subtraction. >>> >>>You can't, because of overflow. >> >>Actually, since integers in OCaml are limited to (n-1) bits where n=32 >>or n=64 depending on architecture, overflow shouldn't be a problem. > > > compare must eventually return an OCaml int. It can use subtraction > only in its internal recursion, but when presenting the result to > OCaml code it can't just pass the result of subtraction. > > It can use subtraction internally no matter whether the OCaml > interface uses intergers whose sign only matters, or an enumeration. > > And thus there seems to be no performance advantage in using ints > instead of the enumeration. > > In practice it returns -1,0,1 anyway: > # compare 10 20;; > - : int = -1 > Indeed, I mistook compare_val for caml_compare. Still if you can make sufficient guarantees about the ranges of the integers being compared, you *can* use '-' which *should* be faster than branching according to conventional wisdom. The more 'relaxed' requirement that comparison functions can return anything<0, 0 or anything>0 just means that any higher-order functions which take comparison functions as arguments *might* run slightly faster... whether this is true in practise is another matter entirely. Cheers, -- Bardur Arantsson It's not often you see something that's both romantic *and* thrifty. Dawn, 'The Office'