swift-foundation
swift-foundation copied to clipboard
Implement Locale's identifier from components in Swift
Implement Locale's identifier(from:) in Swift.
Perf test:
let c1 = ["kCFLocaleLanguageCodeKey" : "en"]
let c2 = ["kCFLocaleLanguageCodeKey" : "zh",
"kCFLocaleScriptCodeKey" : "Hans",
"kCFLocaleCountryCodeKey" : "TW"]
let c3 = ["kCFLocaleLanguageCodeKey" : "es",
"kCFLocaleScriptCodeKey" : "",
"kCFLocaleCountryCodeKey" : "409"]
for _ in 0..<100_000 {
let id1 = Locale.identifier(fromComponents: c1)
let id2 = Locale.identifier(fromComponents: c2)
let id3 = Locale.identifier(fromComponents: c3)
assert(id1.isEmpty == false)
assert(id2.isEmpty == false)
assert(id3.isEmpty == false)
}
And the results:
// Swift implementation
test_identifierFromComponents() 0.040965125 seconds
test_identifierFromComponents() 0.039983875 seconds
// Previous CF implementation, from Swift
test_identifierFromComponents() 0.35747675 seconds
test_identifierFromComponents() 0.357553 seconds
Part of issue #45 Resolves rdar://108618701
Hm, do we have a good place to put perf tests yet?
Yup, you're 100% correct. Will revise.
@swift-ci test
@swift-ci test
@swift-ci please test
@swift-ci test
@swift-ci test