From: Paul Shirley Newsgroups: comp.os.msdos.djgpp Subject: Re: floats v doubles myth Date: Sat, 8 Feb 1997 10:08:26 +0000 Organization: wot? me? Lines: 46 Distribution: world Message-ID: References: <32f2a072 DOT 17736424 AT news DOT ionsys DOT com> <32f3a643 DOT 25054189 AT news DOT ox DOT ac DOT uk> <32F7CE6F DOT 16DF AT pobox DOT oleane DOT com> Reply-To: Paul Shirley NNTP-Posting-Host: chocolat.foobar.co.uk Mime-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32F7CE6F DOT 16DF AT pobox DOT oleane DOT com>, Francois Charton writes >Myth ? which myth? This is true. >Try this : > >#include >#include >#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