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

Date: Sun, 5 Jan 1997 23:34:45 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: djgpp AT delorie DOT com
Subject: FP vs int timings
Message-ID: <Pine.GSO.3.95.970105232426.17458A-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

	I have been unable to reproduce the claim that integer
instructions are "thousands" of times faster than floating-point in DJGPP:

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define	ITERATIONS	1000000

int	main()
{
	volatile double	a, b, c; /* make sure they aren't optimized away*/
	volatile int	x, y, z;
	int	i;
	uclock_t	start_time, end_time;

	srand(time(NULL));

	start_time = uclock();
	for (i = 0; i < ITERATIONS; i++)
	{
		b = (double)random();
		c = (double)random();
		a = b / c;
	}
	end_time = uclock();

	printf("Time for %d doubles:  %.2fs\n", ITERATIONS,
		(double)(end_time - start_time) / UCLOCKS_PER_SEC);

	start_time = uclock();
	for (i = 0; i < ITERATIONS; i++)
	{
		y = (int)random();
		z = (int)random();
		x = y / z;
	}
	end_time = uclock();

	printf("Time for %d ints:  %.2fs\n", ITERATIONS,
		(double)(end_time - start_time) / UCLOCKS_PER_SEC);

	return 0;
}

results on my 5x86/100 under Win95:
	doubles:  2.29s for 1000000 divides
	ints:     2.12s for 1000000 divides

conclusions:  on my machine, at least, there is not a significant
difference in speed between integer and floating-point math.  (The program
was compiled with -O2, by the way).

						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine

- Raw text -


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