www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/04/22:13:46

From: leathm AT solwarra DOT gbrmpa DOT gov DOT au (Leath Muller)
Message-Id: <199702050248.MAA19073@solwarra.gbrmpa.gov.au>
Subject: Re: floats v doubles myth
To: djgpp AT delorie DOT com
Date: Wed, 5 Feb 1997 12:48:41 +1000 (EST)
In-Reply-To: <32F7CE6F.16DF@pobox.oleane.com> from "Francois Charton" at Feb 5, 97 01:03:59 am

> 
> 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