Mail Archives: djgpp/1997/02/04/22:13:46
>
> 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 -