swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

Implement Locale's identifier from components in Swift

Open parkera opened this issue 2 years ago • 1 comments

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

parkera avatar Apr 27 '23 18:04 parkera

Hm, do we have a good place to put perf tests yet?

parkera avatar Apr 27 '23 23:04 parkera

Yup, you're 100% correct. Will revise.

parkera avatar May 01 '23 17:05 parkera

@swift-ci test

parkera avatar May 03 '23 20:05 parkera

@swift-ci test

parkera avatar May 03 '23 20:05 parkera

@swift-ci please test

itingliu avatar May 08 '23 17:05 itingliu

@swift-ci test

parkera avatar May 12 '23 17:05 parkera

@swift-ci test

parkera avatar May 12 '23 17:05 parkera