简体   繁体   English

在原始类型上快速扩展的性能

[英]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.

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