cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/08/18:53:05

From: Paul Shirley <Paul AT foobar DOT co DOT uk DOT chocolat>
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: <FThq$DAaCF$yEwYq@foobar.co.uk>
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>
<32F7CE6F DOT 16DF AT pobox DOT oleane DOT com>
Reply-To: Paul Shirley <junk AT defeating DOT email DOT address>
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
<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 -


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