Calendar.current.date(bySettingHour takes so long to compile

China☆狼群 提交于 2019-12-31 08:00:07

问题


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 ?


回答1:


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.

When I compile this with swiftc it takes less than half a second. It runs in less than a second.



来源:https://stackoverflow.com/questions/55627683/calendar-current-datebysettinghour-takes-so-long-to-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!