Mail Archives: djgpp/1997/02/08/18:53:05
In article <32F7CE6F DOT 16DF AT pobox DOT oleane DOT com>, Francois Charton
<deef AT pobox DOT oleane DOT com> writes
>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;
####
uclock(); /* start the timer and load into cache */
>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.
Add the extra uclock() call marked and try again. You will be
disappointed ;)
Your first call to uclock() incurrs extra time including loading the
routined into code cache... that screws up the results.
However this test is totally pointless, since I assume if speed is so
important there will be a lot of calculation going on. And typically
that would mean working with arrays of numbers. At which point the
cache/memory effects will start to show.
---
Paul Shirley: shuffle chocolat before foobar for my real email address
- Raw text -