www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/04/19:15:11

Message-ID: <32F7CE6F.16DF@pobox.oleane.com>
Date: Wed, 05 Feb 1997 01:03:59 +0100
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: floats v doubles myth
References: <32f2a072 DOT 17736424 AT news DOT ionsys DOT com>
<32f3a643 DOT 25054189 AT news DOT ox DOT ac DOT uk> <Jyj5XLAaMk9yEwb1 AT foobar DOT co DOT uk>

Paul Shirley wrote:
> 
> >Doubles are more accurate and apparently faster than floats.
>                                           ^^^^^^
> Can we *please* kill this myth.
> On Pentium there is NO speed difference between using a float or double.
> On 387,486/487 float is slightly *faster* to load, store or read from
> ram as an operand, than a double.
> 

Myth ? which myth? This is true.
Try this : 

#include <stdio.h>
#include <time.h>
#define PI 3.141592

void main(void)
{
float f,g;
double d,e;
int l1,l2,l3;
l1=uclock();  /* highres timer : one tick is about 0.8 microsecond */
f=PI;
g=2.1;
g+=f*f*f;    /* two muls, one add, two loads, in float */
l2=uclock();
d=PI;
e=2.1;
d+=e*e*e;   /* just the same in double */
l3=uclock();
printf("%d %d\n",l2-l1, l3-l2);  /* time all this */
}

On my 486dx75, this program prints "20 12", which means the calculation 
in floats is about twice slower than the calculation in doubles.

As you can see, there are no fancy functions with prototypes in doubles 
involved, just plain multiplies and adds...

I have no Pentium handy to test this, but I suspect the same will happen: 
if you look at the code produced by DJGPP, you'll notice that the float 
version has a few more instructions than the double version (cast 
instructions actually)... 

Francois

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019