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.