From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 3BB25BC84 for ; Fri, 1 Apr 2005 07:59:36 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j315xZY5026611 for ; Fri, 1 Apr 2005 07:59:35 +0200 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 HAA25957 for ; Fri, 1 Apr 2005 07:59:35 +0200 (MET DST) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j315xYqK026608 for ; Fri, 1 Apr 2005 07:59:35 +0200 Received: from [192.168.1.100] (charter-242-004.caltech.edu [131.215.242.4]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 72E50DF2D3 for ; Thu, 31 Mar 2005 21:59:33 -0800 (PST) Message-ID: <424CE344.20409@cs.caltech.edu> Date: Thu, 31 Mar 2005 21:59:32 -0800 From: Aleksey Nogin Organization: California Institute of Technology, Computer Science Department User-Agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Caml List Subject: Re: [Caml-list] Re: Pervasives.compare output type References: <42430B3B.60408@barettadeit.com> <20050324194115.GB9518@furbychan.cocan.org> <87acosu5c9.fsf@qrnik.zagroda> <42433A1C.2060203@cs.caltech.edu> <4243DD0D.1060100@barettadeit.com> In-Reply-To: <4243DD0D.1060100@barettadeit.com> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 424CE347.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 424CE346.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 pervasives:01 baretta:01 pervasives:01 pairs:01 hash:01 ...:98 wrote:01 pair:01 ints:01 int:01 int:01 caltech:02 caltech:02 match:02 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: On 25.03.2005 01:42, Alex Baretta wrote: >>> let f1 x y = Pervasives.compare x y >>> let f2 (x: int) y = Pervasives.compare x y >>> let f3 x y = if x=y then Pervasives.compare "s1" "s2" else if >>> x < y then -1 else 1 >>> let f4 (x: int) y = if x=y then Pervasives.compare "s1" "s2" else if >>> x < y then -1 else 1 >>> let f5 x y = let i = Pervasives.compare x y in if i = 0 then >>> Pervasives.compare "s1" "s2" else i >>> let f6 (x: int) y = let i = Pervasives.compare x y in if i = 0 then >>> Pervasives.compare "s1" "s2" else i >>> let f7 x y = match Pervasives.compare x y with 0 -> >>> Pervasives.compare "s1" "s2" | i -> i >>> let f8 (x: int) y = match Pervasives.compare x y with 0 -> >>> Pervasives.compare "s1" "s2" | i -> i >>> >>> let time name f = >>> > > > I am unsure as to how to interpret these benchmarks... Yes, these were taken a bit out of context. Basically, the question we were discussing was: > What's the fastest way to compare int*string pairs (or, in general - int*'a), where ints are likely to be distinct whenever the second elements are distinct (basically, the int is a hash)? The answer is that the "f4" above is the fastest one: let compair_pair ((i1:int), a1) (i2, a2) = if i1 = i2 then Pervasives.compare a1 a2 else if i1 < i2 then -1 else 1 -- Aleksey Nogin Home Page: http://nogin.org/ E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal) Office: Moore 04, tel: (626) 395-2200