delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/05/23:08:53

From: aho450s AT nic DOT smsu DOT edu (Tony O'Bryan)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Fixed Point (Optimization)
Date: Mon, 06 Jan 1997 02:36:25 GMT
Organization: Southwest Missouri State University
Lines: 66
Message-ID: <32d0610c.1680703@ursa.smsu.edu>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970105181744 DOT 22565V-100000 AT is>
NNTP-Posting-Host: forseti.i31.smsu.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Sun, 5 Jan 1997 16:19:51 GMT, Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
wrote:

>
>On Sat, 4 Jan 1997, Tony O'Bryan wrote:
>
>> I did a quick check on floating point vs. integers not too long ago.
>> I wrote a small loop that only added an integer to an integer counter,
>> then rewrote it using floating point variables.  On my Pentium 120,
>> integers were THOUSANDS of times faster.
>
>I don't see how this can be true, even on a 486, let alone Pentium.  Look 
>at the cycle counts for the operations, they only differ by a factor of 2 
>to 10, definitely not thousands.
>
>Can you post a program which exhibits the above, and the timing that you 
>get on your system?

My computer betrays me once again.  I rewrote a simple timing program
that merely calculates elapsed time using clock() and divides by
CLK_TCK.  _THIS TIME_ I ran it through 500,000 loops just adding 100.0
to a type double accumulator.  Once the floating point loop finished,
I repeated the loop using a type long as my accumulator.  On my
Pentium 120, the floating point addition loop was roughly half as fast
as the addition loop.  The elapsed time was miniscule, not nearly the
same results I had gotten previously.

When I previously wrote a similar program (the one I mentioned in my
first post), my computer delayed noticably during the floating point
loop.  This time there was no delay at all.

Here's the code to the recent program:

#include <time.h>
#include <conio.h>

main()
  {
  clock_t                       StartTime,EndTime;
  unsigned long                 Count,IntNumber;
  double                        DoubleNumber,Result;

  clrscr();
  StartTime = clock();
  for (Count = 0L,DoubleNumber = 0.0;Count < 500000L;Count++)
    DoubleNumber += (double)100.0;
  EndTime = clock();
  printf("Elapsed time for 500,000 floating point additions: %4.8f
seconds\n",Result = (double)(EndTime - StartTime) / (double)CLK_TCK);
  printf("        that's %4.8f seconds per add\n",Result /
(double)500000.0);

  StartTime = clock();
  for (Count = 0L,IntNumber = 0;Count < 500000L;Count++)
    IntNumber += 100L;
  EndTime = clock();
  printf("Elapsed time for 500,000 integer additions: %4.8f
seconds\n",Result = (double)(EndTime - StartTime) / (double)CLK_TCK);
  printf("        that's %4.8f seconds per add\n",Result /
(double)500000.0);
  }

Yuck!  I hope your mail reader doesn't mangle the code like mine did.
This code was written using Turbo C++ 3.0.  And here's hoping I didn't
stick my foot into my mouth again... *crosses fingers*

- Raw text -


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