Pervasives.compare output type
[
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:   (:) 
From:  Aleksey Nogin <nogin@c...> 
Subject:  Re: [Camllist] Re: Pervasives.compare output type 
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/ EMail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal) Office: Moore 04, tel: (626) 3952200