1313import Benchmark
1414import func Benchmark. blackHole
1515
16- #if FOUNDATION_FRAMEWORK // This test uses CFString
16+ #if os(macOS) && USE_PACKAGE
17+ import FoundationEssentials
18+ import FoundationInternationalization
19+ #else
1720import Foundation
21+ #endif
1822
1923let benchmarks = {
2024 Benchmark . defaultConfiguration. maxIterations = 1_000
2125 Benchmark . defaultConfiguration. maxDuration = . seconds( 3 )
2226 Benchmark . defaultConfiguration. scalingFactor = . kilo
23- Benchmark . defaultConfiguration. metrics = [ . cpuTotal, . wallClock, . mallocCountTotal , . throughput ]
27+ Benchmark . defaultConfiguration. metrics = [ . cpuTotal, . wallClock, . throughput , . peakMemoryResident , . peakMemoryResidentDelta ]
2428
29+ #if FOUNDATION_FRAMEWORK
2530 let string1 = " aaA " as CFString
2631 let string2 = " AAà " as CFString
2732 let range1 = CFRange ( location: 0 , length: CFStringGetLength ( string1) )
@@ -34,5 +39,22 @@ let benchmarks = {
3439 CFStringCompareWithOptionsAndLocale ( string1, string2, range1, . init( rawValue: 0 ) , nsLocale)
3540 }
3641 }
37- }
3842#endif
43+
44+ let identifiers = Locale . availableIdentifiers
45+ let allComponents = identifiers. map { Locale . Components ( identifier: $0) }
46+ Benchmark ( " LocaleInitFromComponents " ) { benchmark in
47+ for components in allComponents {
48+ let locale = Locale ( components: components)
49+ let components2 = Locale . Components ( locale: locale)
50+ let locale2 = Locale ( components: components2) // cache hit
51+ }
52+ }
53+
54+ Benchmark ( " LocaleComponentsInitIdentifer " ) { benchmark in
55+ for identifier in identifiers {
56+ let components = Locale . Components ( identifier: identifier)
57+ }
58+ }
59+ }
60+
0 commit comments