From: Bardur Arantsson <spam@scientician.net>
To: caml-list@inria.fr
Subject: Re: Pervasives.compare output type
Date: Thu, 24 Mar 2005 23:41:49 +0100 [thread overview]
Message-ID: <d1vfn3$p6g$1@sea.gmane.org> (raw)
In-Reply-To: <87d5ton11t.fsf@qrnik.zagroda>
Marcin 'Qrczak' Kowalczyk wrote:
> Bardur Arantsson <spam@scientician.net> 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
<bardur@imada.sdu.dk>
<bardur@scientician.net>
It's not often you see something that's both romantic *and*
thrifty.
Dawn, 'The Office'
next prev parent reply other threads:[~2005-03-24 22:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-24 18:47 Alex Baretta
2005-03-24 19:41 ` [Caml-list] " Richard Jones
2005-03-24 21:00 ` Marcin 'Qrczak' Kowalczyk
2005-03-24 21:38 ` Bardur Arantsson
2005-03-24 22:07 ` [Caml-list] " Jason Hickey
2005-03-24 22:26 ` brogoff
2005-03-25 9:42 ` Alex Baretta
2005-04-01 5:59 ` Aleksey Nogin
2005-03-24 22:15 ` Marcin 'Qrczak' Kowalczyk
2005-03-24 22:41 ` Bardur Arantsson [this message]
2005-03-25 9:43 ` Alex Baretta
2005-03-29 7:14 ` [Caml-list] " Oliver Bandel
2005-03-30 14:17 ` Xavier Leroy
2005-03-30 14:45 ` Alex Baretta
2005-03-30 15:11 ` Jacques Carette
2005-03-30 15:28 ` Alex Baretta
2005-03-30 17:47 ` brogoff
2005-03-30 18:21 ` Jacques Carette
2005-03-30 18:49 ` brogoff
2005-03-30 20:06 ` Jon Harrop
2005-03-30 20:43 ` Jacques Carette
2005-03-30 22:14 ` Christopher Dutchyn
2005-03-31 0:44 ` brogoff
2005-03-30 22:43 ` GADT?? (Re: [Caml-list] Pervasives.compare output type) Oliver Bandel
2005-03-30 22:35 ` [Caml-list] Pervasives.compare output type Oliver Bandel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='d1vfn3$p6g$1@sea.gmane.org' \
--to=spam@scientician.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox