Is Multiplying the Inverse Better or Worse?

前端 未结 11 1193
忘了有多久
忘了有多久 2020-12-20 13:52

When dealing with double data types is multiplying by the inverse better or worse?

Which way is faster? Which way uses

11条回答
  •  时光取名叫无心
    2020-12-20 14:45

    Which one is "faster" is indeed a cpu-specific issue, or at least how much faster is CPU specific, yes, division is typically seen as slower than multiplication. And of course all performance questions can be answered with "it depends."

    HOWEVER, if you'd asked which is "better" rather than which is faster there would be a clear answer, the more readable one is better. The performance improvement you're looking at is likely on the order of several clock cycles, so unless you're talking about doing this millions of times, you're trying to save yourself microseconds. And there is no microsecond optimization that is worth sacrificing readability and maintainability.

提交回复
热议问题