From 813b114aa2384bd928ee9c673264f56bd7340981 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 25 Jun 2019 15:20:17 -0700 Subject: [PATCH] Add a benchmark for unicode Strings created via JSON decoding --- .../single-source/ObjectiveCBridging.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/benchmark/single-source/ObjectiveCBridging.swift b/benchmark/single-source/ObjectiveCBridging.swift index 6ce0131969c9e..bf66d49abe74e 100644 --- a/benchmark/single-source/ObjectiveCBridging.swift +++ b/benchmark/single-source/ObjectiveCBridging.swift @@ -76,6 +76,9 @@ public let ObjectiveCBridging = [ BenchmarkInfo(name: "ObjectiveCBridgeASCIIStringFromFile", runFunction: run_ASCIIStringFromFile, tags: ts, setUpFunction: setup_ASCIIStringFromFile), + BenchmarkInfo(name: "UnicodeStringFromCodable", + runFunction: run_UnicodeStringFromCodable, tags: ts, + setUpFunction: setup_UnicodeStringFromCodable), ] #if _runtime(_ObjC) @@ -744,3 +747,25 @@ public func run_ASCIIStringFromFile(_ N: Int) { #endif } +var unicodeStringFromCodable:String? = nil +var unicodeStringFromCodableDict = [String:Void]() +public func setup_UnicodeStringFromCodable() { + let jsonString = "[\(String(reflecting: string))]" + + let decoded = try JSONDecoder().decode([String].self, from: Data(jsonString.utf8)) + let reEncoded = try JSONEncoder().encode(decoded) + let desc = try JSONDecoder().decode([String].self, from: reEncoded) + + unicodeStringFromCodable = desc[0] +} + +@inline(never) +public func run_UnicodeStringFromCodable(_ N: Int) { + #if _runtime(_ObjC) + for _ in 0 ..< N { + for _ in 0..<100 { + unicodeStringFromCodableDict[identity(unicodeStringFromCodable)] = () + } + } + #endif +}