Calendar.current.date(bySettingHour需要很长时间才能编译

问题描述 投票:-4回答:1

我使用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

有没有办法减少编译时间?

ios swift nsdate nscalendar
1个回答
2
投票

您无法在Playground中测试性能,而且最重要的是无法编译性能。游乐场做了很多额外的工作,在右栏中显示“(9999次)”。操场上也没有单独的“编译”步骤,您可以将其与执行分开。而且他们没有优化代码。您无法在Playground中评估性能的任何部分。

当我使用swiftc编译它时,它只需不到半秒钟。它运行不到一秒钟。

© www.soinside.com 2019 - 2024. All rights reserved.