What's the relative speed of floating point add vs. floating point multiply

后端 未结 6 1206
小鲜肉
小鲜肉 2020-12-01 10:48

A decade or two ago, it was worthwhile to write numerical code to avoid using multiplies and divides and use addition and subtraction instead. A good example is using forwa

6条回答
  •  忘掉有多难
    2020-12-01 11:10

    I can't find a definitive reference, but extensive experimentation tells me that float multiplication nowadays is just about the same speed as addition and subtraction, while division isn't (but not "many times" slower, either). You can get the intuition you desire only by running your own experiments -- remember to generate the random numbers (millions of them) in advance, read them before you start timing, and use the CPU's performance counters (with no other process running, as much as you can stop them from) for accurate measurement!

提交回复
热议问题