Skip to content

Commit ec1a690

Browse files
authored
Merge pull request swiftlang#25765 from Catfish-Man/bridged-normalization-bench
Add a benchmark for unicode Strings created via JSON decoding
2 parents f2db641 + 813b114 commit ec1a690

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public let ObjectiveCBridging = [
7676
BenchmarkInfo(name: "ObjectiveCBridgeASCIIStringFromFile",
7777
runFunction: run_ASCIIStringFromFile, tags: ts,
7878
setUpFunction: setup_ASCIIStringFromFile),
79+
BenchmarkInfo(name: "UnicodeStringFromCodable",
80+
runFunction: run_UnicodeStringFromCodable, tags: ts,
81+
setUpFunction: setup_UnicodeStringFromCodable),
7982
]
8083

8184
#if _runtime(_ObjC)
@@ -744,3 +747,25 @@ public func run_ASCIIStringFromFile(_ N: Int) {
744747
#endif
745748
}
746749

750+
var unicodeStringFromCodable:String? = nil
751+
var unicodeStringFromCodableDict = [String:Void]()
752+
public func setup_UnicodeStringFromCodable() {
753+
let jsonString = "[\(String(reflecting: string))]"
754+
755+
let decoded = try JSONDecoder().decode([String].self, from: Data(jsonString.utf8))
756+
let reEncoded = try JSONEncoder().encode(decoded)
757+
let desc = try JSONDecoder().decode([String].self, from: reEncoded)
758+
759+
unicodeStringFromCodable = desc[0]
760+
}
761+
762+
@inline(never)
763+
public func run_UnicodeStringFromCodable(_ N: Int) {
764+
#if _runtime(_ObjC)
765+
for _ in 0 ..< N {
766+
for _ in 0..<100 {
767+
unicodeStringFromCodableDict[identity(unicodeStringFromCodable)] = ()
768+
}
769+
}
770+
#endif
771+
}

0 commit comments

Comments
 (0)