Avatar
Avatar
Iceman
@swift-6.0.3 -O import Foundation let iso8601String = "2023-10-09T16:34:23Z" let iterations = 1000 // ISO8601DateFormatter let iso8601DateFormatter = ISO8601DateFormatter() var iso8601DateFormatterTime: TimeInterval = 0 for _ in 0..<iterations { let start = Date() _ = iso8601DateFormatter.date(from: iso8601String) let end = Date() iso8601DateFormatterTime += end.timeIntervalSince(start) } // Date.ISO8601FormatStyle var iso8601FormatStyleTime: TimeInterval = 0 for _ in 0..<iterations { let start = Date() _ = try? Date(iso8601String, strategy: .iso8601) let end = Date() iso8601FormatStyleTime += end.timeIntervalSince(start) } print("ISO8601DateFormatter Time: \(iso8601DateFormatterTime) seconds") print("Date.ISO8601FormatStyle Time: \(iso8601FormatStyleTime) seconds")
ISO8601DateFormatter Time: 0.6819443702697754 seconds Date.ISO8601FormatStyle Time: 0.002825140953063965 seconds