【发布时间】:2019-09-01 19:19:51
【问题描述】:
我使用Calendar.current.date(bySettingHour 代码来设置特定日期。问题是编译需要很长时间~4 秒
print("Time seconds ",Date().timeIntervalSince1970)
for i in 0..<9999 {
let nowDate = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: Date())!
}
print("Time seconds ",Date().timeIntervalSince1970)// For loop took 4 seconds
有什么办法可以减少编译时间?
【问题讨论】:
-
你的意思是编译还是运行需要4秒?
-
@Chris 编译时间。您可以通过在操场上粘贴代码来检查
-
我没有在当前的 XCode 版本中使用 Playgrounds,但是与我以前使用的 Playgrounds 相比,4 秒对于 Playgrounds 来说是相当快的。
-
您永远不应该在 Playground 中检查性能,无论是编译时性能还是运行时性能,因为 Playground 不使用优化。
-
对我来说花了 2 秒.. :)
标签: ios swift nsdate nscalendar