可能重复:
浮点除法与浮点乘法
最近,我编写了一个计算计算机实际乘法、除法和加法所需时间的程序。
为此,我使用了函数QueryPerformanceFrequency和QueryPerformanceCounter以获取时间间隔。
我已经使用600万次迭代对我的程序进行了测试:6000000个浮点变量的乘法、除法和求和,并得到了以下结果:
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
除法比乘法慢六倍,加法与乘法几乎相等(约为0.42纳秒)?