caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Comparing floats
Date: Tue, 4 Aug 2015 11:06:10 +0200	[thread overview]
Message-ID: <20150804090609.GA5689@frosties> (raw)
In-Reply-To: <55B0B9DE.2070609@freenet.de>

On Thu, Jul 23, 2015 at 11:54:38AM +0200, Mr. Herr wrote:
> 
> 
> On 23.07.2015 11:01, Xavier Leroy wrote:
> >On 23/07/2015 10:35, Sébastien Hinderer wrote:
> >>What's the most efficient way to compare floats, please?
> >>Is it the polymorphic compare function, or is there a more specialized
> >>version of it?
> >You'll get good performance by type-specializing Pervasives.compare:
> >
> >let compare_float (x: float) (y: float) = compare x y
> >
> >If you're absolutely sure your floats are not NaN, you can shave a few
> >CPU cycles:
> >
> >let compare_float (x: float) (y: float) =
> >   if x < y then -1 else if x > y then 1 else 0
> >
> The assembler code says compare_float is directly compiled to a function
> that compares the 2 values
> in xmm0 and xmm1 registers, while Pervasives.compare is a library function
> written in C doing the same thing.
> 
> The assembler code looks very very good.
> 
> But I doubt that you could measure a difference. The type system will always
> yield the float_compare function, doesn't it? So far my quickcheck...

There are many cases where you have a polymorphic function (as in the
code does not allow to infere that the type is float) doing lots of
compares or you pass compare as argument to a polymorphic function. By
specifically forcing the type to be float you can gain a lot of
performance.

If the type system already inferes the float type itself then you gain
nothing. But that doesn't always happen (at the right time).

MfG
	Goswin

  reply	other threads:[~2015-08-04  9:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23  8:35 Sébastien Hinderer
2015-07-23  8:46 ` Francois Berenger
2015-07-23  9:05   ` Mr. Herr
2015-07-23  9:01 ` Xavier Leroy
2015-07-23  9:35   ` Sébastien Hinderer
2015-07-23  9:54   ` Mr. Herr
2015-08-04  9:06     ` Goswin von Brederlow [this message]
2015-07-23 11:34 ` Boris Yakobowski
2015-07-23 15:14   ` Jacques-Henri Jourdan
2015-07-23 16:34     ` Boris Yakobowski
2015-07-23 17:00       ` Xavier Leroy

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=20150804090609.GA5689@frosties \
    --to=goswin-v-b@web.de \
    --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;
as well as URLs for NNTP newsgroup(s).