Possible Duplicate:
Floating point division vs floating point multiplication
recently, i have written a program that calculates how long it takes my computer
to calculate real multiplications, divisions and additions.
for that, i have used the functions QueryPerformanceFrequency and QueryPerformanceCounter
in order to get time intervals.
i have tested my program using 6,000,000 iterations : 6000000 multiplications, divisions and sums (with float variables), and get this results:
O.S = Windows Vista (TM) Home Premium, 32-bit (Service Pack 2)
Processor = Intel Core (TM)2 Quad CPU Q8200
Processor Freq = 2.33 GHz
Compiler = Visual C++ Express Edition
nº iterations time in micro seconds
6000000 x real mult + assignment -> 15685.024214 us
6000000 x real div + assignment -> 51737.441490 us
6000000 x real sum + assignment -> 15448.471803 us
6000000 x real assignment -> 12987.614348 us
nº iterations time in micro seconds
6000000 x real mults -> 2697.409866 us
6000000 x real divs -> 38749.827143 us
6000000 x real sums -> 2460.857455 us
1 Iteration time in nano seconds
real mult -> 0.449568 ns
real div -> 6.458305 ns
real sum -> 0.410143 ns
Is it possible that the division is six times slower than multiplication, and
addition practically equal than multiplication (~ 0.42 ns) ?
Yes it is. If you have ever done division manually, then you know that it involves lots of sub-operations.
As for addition vs. multiplication being about the same speed: those have more to do with setting up the operands and storing the result than the actual computation. You might be able to get more difference between them by compiling using SSE instructions for addition and multiplication (on x86).