简体   繁体   中英

Performance of swift extensions on primitive types

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())

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM