Performance of swift extensions on primitive types

≯℡__Kan透↙ 提交于 2019-12-11 06:25:36

问题


I am wondering if there would be any performance difference between the following in swift:

let x = 42.42
print(floor(x))

and

let x = 42.42
extension Double {
  func myFloor() -> Double {
    return floor(self)
  }
}
print(x.myFloor())

回答1:


The compiler inlines the code in the second case and produces the same machine code. You can see for yourself, here.



来源:https://stackoverflow.com/questions/45558276/performance-of-swift-extensions-on-primitive-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!