[英]Performance of swift extensions on primitive types
I am wondering if there would be any performance difference between the following in swift
: 我想知道
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.
你可以在这里看到自己。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.