Mail Archives: djgpp/1997/01/05/23:40:01
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 -