问题
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