We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
md5: b3d9b9b721bcab10408898f706efbe14
Issue Description:
DateComponents.date is slow on Linux.
It's slower than DateFormatter.date which should be less efficient.
import Foundation let iteration = 10_000 let year = 2019 let month = 11 let day = 10 let hour = 10 let minute = 10 let second = 10 let microsecond = 101010 func testDateComponents() { var comps = DateComponents( calendar: Calendar(identifier: .gregorian), timeZone: TimeZone(secondsFromGMT: 0)! ) comps.year = year comps.month = month comps.day = day comps.hour = hour comps.minute = minute comps.second = second comps.nanosecond = microsecond*1000 let start = Date() var total: TimeInterval = 0 for _ in 0..<iteration { total += comps.date?.timeIntervalSinceNow ?? 0 } print("DateComponents: \(Date().timeIntervalSince(start))sec, \(total)") } func testDateFormatter() { let df = DateFormatter() df.dateFormat = "yyyy/MM/dd HH:mm:ss.SSSSSSS" let start = Date() var total: TimeInterval = 0 for _ in 0..<iteration { let date = df.date(from: "\(year)/\(month)/\(day) \(hour):\(minute):\(second).\(microsecond)") total += date?.timeIntervalSinceNow ?? 0 } print("DateFormatter: \(Date().timeIntervalSince(start))sec, \(total)") } testDateComponents() testDateFormatter()
On macOS(2.7 GHz Intel Core i7):
$ swift --version Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7) Target: x86_64-apple-darwin18.7.0 $ swiftc -O main.swift $ ./main DateComponents: 0.012930989265441895sec, 14041821731.490162 DateFormatter: 0.2265690565109253sec, 13717820468.565754
On Ubuntu(Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz):
$ swift --version Swift version 5.1.1 (swift-5.1.1-RELEASE) Target: x86_64-unknown-linux-gnu $ swiftc -O main.swift $ ./main DateComponents: 0.5204849243164062sec, 14032373021.035366 DateFormatter: 0.28744006156921387sec, 14032368951.859718
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Additional Detail from JIRA
md5: b3d9b9b721bcab10408898f706efbe14
Issue Description:
DateComponents.date is slow on Linux.
It's slower than DateFormatter.date which should be less efficient.
On macOS(2.7 GHz Intel Core i7):
On Ubuntu(Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz):
The text was updated successfully, but these errors were encountered: