Mail Archives: djgpp/1997/01/06/16:46:28
Michael Phelps wrote:
>
> b = (double)random();
> c = (double)random();
> a = b / c;[snip]
> y = (int)random();
> z = (int)random();
> x = y / z;[resnip]
> 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
If you want to compare their speed, you have to test fixed vs float on
more than just a divide...
As an example, fixed point math usually are good at addition and
substraction, and I think the compares could also be quite fast.
OTOH, fixed by fixed multiplies and divisions are slow (as you have
noticed, in fact their are even worse than in your program, because there
is one more shift involved)...
But fixed by integer multiplies and divides are fast, and cast from int
to fixed also are... and with fixed point numbers, you can index
arrays...
The list could go on.
To me, on most modern machines (anything with a built in FPU basically),
integer calculations are not significantly faster than floating point
instructions *on the average*. However, if speed is a concern, they are
worth experimenting with, they can help a lot at times...
Francois
- Raw text -