Calendar.current.date(bySettingHour编译需要花费很长时间 [英] Calendar.current.date(bySettingHour takes so long to compile
问题描述
我已使用Calendar.current.date(bySettingHour
代码设置特定日期.问题是,编译大约需要4秒钟的时间
I have used Calendar.current.date(bySettingHour
code for setting particular date. Problem is it takes so long to compile ~4 seconds
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
有什么方法可以减少编译时间?
Is there any way to reduce compile time ?
推荐答案
您不能在Playground中测试性能,并且大多数情况下不能编译性能.游乐场要做很多额外的工作,以在右侧栏中显示(9999次)".游乐场也实际上没有单独的编译"步骤,您可以将其与执行分开.而且他们不会优化代码.您无法在Playground中评估任何性能.
You can't test performance in a Playground, and most of all not compile performance. Playgrounds do a lot of extra work to display "(9999 times)" in the right-hand column. Playgrounds also don't really have a separate "compile" step that you can separate from execution. And they don't optimize the code. There's no part of performance that you can evaluate in a Playground.
当我用swiftc编译它时,它花费不到半秒钟的时间.它运行不到一秒钟.
When I compile this with swiftc it takes less than half a second. It runs in less than a second.
这篇关于Calendar.current.date(bySettingHour编译需要花费很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!