From fa6c038c9213f6b42321b25fca6acde06ad7e1b9 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 26 Oct 2020 17:56:42 +0100 Subject: [PATCH 1/8] Adds benchmarks for UTF16 decoding --- benchmark/CMakeLists.txt | 1 + benchmark/single-source/UTF16Decode.swift | 210 ++++++++++++++++++++++ benchmark/utils/main.swift | 2 + 3 files changed, 213 insertions(+) create mode 100644 benchmark/single-source/UTF16Decode.swift diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 8ba0050e0d758..62e366f13f599 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -198,6 +198,7 @@ set(SWIFT_BENCH_MODULES single-source/TwoSum single-source/TypeFlood single-source/UTF8Decode + single-source/UTF16Decode single-source/Walsh single-source/WordCount single-source/XorLoop diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift new file mode 100644 index 0000000000000..79614e0c17ac8 --- /dev/null +++ b/benchmark/single-source/UTF16Decode.swift @@ -0,0 +1,210 @@ +//===--- UTF16Decode.swift -------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import TestsUtils +import Foundation + +public let UTF16Decode = [ + BenchmarkInfo( + name: "UTF16Decode", + runFunction: run_UTF16Decode, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromCustom_contiguous", + runFunction: run_UTF16Decode_InitFromCustom_contiguous, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromCustom_contiguous_ascii", + runFunction: run_UTF16Decode_InitFromCustom_contiguous_ascii, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromCustom_noncontiguous", + runFunction: run_UTF16Decode_InitFromCustom_noncontiguous, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromCustom_noncontiguous_ascii", + runFunction: run_UTF16Decode_InitFromCustom_noncontiguous_ascii, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromData", + runFunction: run_UTF16Decode_InitFromData, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitDecoding", + runFunction: run_UTF16Decode_InitDecoding, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromData_ascii", + runFunction: run_UTF16Decode_InitFromData_ascii, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitDecoding_ascii", + runFunction: run_UTF16Decode_InitDecoding_ascii, + tags: [.validation, .api, .String]), + BenchmarkInfo( + name: "UTF16Decode_InitFromData_ascii_as_ascii", + runFunction: run_UTF16Decode_InitFromData_ascii_as_ascii, + tags: [.validation, .api, .String]), +] + +typealias CodeUnit = UInt16 + +// 1-byte sequences +// This test case is the longest as it's the most performance sensitive. +let ascii = "Swift is a multi-paradigm, compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code (\"safer\") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program." +let asciiCodeUnits: [CodeUnit] = Array(ascii.utf16) +let asciiData: Data = asciiCodeUnits.withUnsafeBytes { Data($0) } + +// 2-byte sequences +let russian = "Ру́сский язы́к один из восточнославянских языков, национальный язык русского народа." +// 3-byte sequences +let japanese = "日本語(にほんご、にっぽんご)は、主に日本国内や日本人同士の間で使われている言語である。" +// 4-byte sequences +// Most commonly emoji, which are usually mixed with other text. +let emoji = "Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭." + +let allStrings: [[CodeUnit]] = [ascii, russian, japanese, emoji].map { Array($0.utf16) } +let allStringsCodeUnits: [CodeUnit] = Array(allStrings.joined()) +let allStringsData: Data = allStringsCodeUnits.withUnsafeBytes { Data($0) } + + +@inline(never) +public func run_UTF16Decode(_ N: Int) { + let strings = allStrings + + func isEmpty(_ result: UnicodeDecodingResult) -> Bool { + switch result { + case .emptyInput: + return true + default: + return false + } + } + + for _ in 1...200*N { + for string in strings { + var it = string.makeIterator() + var utf16 = UTF16() + while !isEmpty(utf16.decode(&it)) { } + } + } +} + +@inline(never) +public func run_UTF16Decode_InitFromData(_ N: Int) { + let input = allStringsData + for _ in 0..<200*N { + blackHole(String(data: input, encoding: .utf16)) + } +} +@inline(never) +public func run_UTF16Decode_InitDecoding(_ N: Int) { + let input: [CodeUnit] = allStringsCodeUnits + for _ in 0..<200*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} + +@inline(never) +public func run_UTF16Decode_InitFromData_ascii(_ N: Int) { + let input = asciiData + for _ in 0..<1_000*N { + blackHole(String(data: input, encoding: .utf16)) + } +} +@inline(never) +public func run_UTF16Decode_InitDecoding_ascii(_ N: Int) { + let input = asciiCodeUnits + for _ in 0..<1_000*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} + +@inline(never) +public func run_UTF16Decode_InitFromData_ascii_as_ascii(_ N: Int) { + let input = asciiData + for _ in 0..<1_000*N { + blackHole(String(data: input, encoding: .ascii)) + } +} + +struct CustomContiguousCollection: Collection { + let storage: [CodeUnit] + typealias Index = Int + typealias Element = CodeUnit + + init(_ codeUnits: [CodeUnit]) { self.storage = codeUnits } + subscript(position: Int) -> Element { self.storage[position] } + var startIndex: Index { 0 } + var endIndex: Index { storage.count } + func index(after i: Index) -> Index { i+1 } + + @inline(never) + func withContiguousStorageIfAvailable( + _ body: (UnsafeBufferPointer) throws -> R + ) rethrows -> R? { + try storage.withContiguousStorageIfAvailable(body) + } +} +struct CustomNoncontiguousCollection: Collection { + let storage: [CodeUnit] + typealias Index = Int + typealias Element = CodeUnit + + init(_ codeUnits: [CodeUnit]) { self.storage = codeUnits } + subscript(position: Int) -> Element { self.storage[position] } + var startIndex: Index { 0 } + var endIndex: Index { storage.count } + func index(after i: Index) -> Index { i+1 } + + @inline(never) + func withContiguousStorageIfAvailable( + _ body: (UnsafeBufferPointer) throws -> R + ) rethrows -> R? { + nil + } +} +let allStringsCustomContiguous = CustomContiguousCollection(allStringsCodeUnits) +let asciiCustomContiguous = CustomContiguousCollection(Array(ascii.utf16)) +let allStringsCustomNoncontiguous = CustomNoncontiguousCollection(allStringsCodeUnits) +let asciiCustomNoncontiguous = CustomNoncontiguousCollection(Array(ascii.utf16)) + +@inline(never) +public func run_UTF16Decode_InitFromCustom_contiguous(_ N: Int) { + let input = allStringsCustomContiguous + for _ in 0..<200*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} +@inline(never) +public func run_UTF16Decode_InitFromCustom_contiguous_ascii(_ N: Int) { + let input = asciiCustomContiguous + for _ in 0..<1_000*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} + +@inline(never) +public func run_UTF16Decode_InitFromCustom_noncontiguous(_ N: Int) { + let input = allStringsCustomNoncontiguous + for _ in 0..<200*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} +@inline(never) +public func run_UTF16Decode_InitFromCustom_noncontiguous_ascii(_ N: Int) { + let input = asciiCustomNoncontiguous + for _ in 0..<1_000*N { + blackHole(String(decoding: input, as: UTF16.self)) + } +} + diff --git a/benchmark/utils/main.swift b/benchmark/utils/main.swift index 47026b7a3d9b0..fe4d7d8beac06 100644 --- a/benchmark/utils/main.swift +++ b/benchmark/utils/main.swift @@ -199,6 +199,7 @@ import SuperChars import TwoSum import TypeFlood import UTF8Decode +import UTF16Decode import Walsh import WordCount import XorLoop @@ -393,6 +394,7 @@ register(SuperChars.benchmarks) register(TwoSum.benchmarks) register(TypeFlood.benchmarks) register(UTF8Decode.benchmarks) +register(UTF16Decode.benchmarks) register(Walsh.benchmarks) register(WordCount.benchmarks) register(XorLoop.benchmarks) From 5daec4f9fc46ebcc8ccc45938fafe331a78ce34d Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Mon, 26 Oct 2020 21:49:43 +0100 Subject: [PATCH 2/8] Apply suggestions from code review Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com> --- benchmark/single-source/UTF16Decode.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index 79614e0c17ac8..eefbc0d8371c4 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -106,6 +106,7 @@ public func run_UTF16Decode_InitFromData(_ N: Int) { blackHole(String(data: input, encoding: .utf16)) } } + @inline(never) public func run_UTF16Decode_InitDecoding(_ N: Int) { let input: [CodeUnit] = allStringsCodeUnits @@ -121,6 +122,7 @@ public func run_UTF16Decode_InitFromData_ascii(_ N: Int) { blackHole(String(data: input, encoding: .utf16)) } } + @inline(never) public func run_UTF16Decode_InitDecoding_ascii(_ N: Int) { let input = asciiCodeUnits @@ -185,6 +187,7 @@ public func run_UTF16Decode_InitFromCustom_contiguous(_ N: Int) { blackHole(String(decoding: input, as: UTF16.self)) } } + @inline(never) public func run_UTF16Decode_InitFromCustom_contiguous_ascii(_ N: Int) { let input = asciiCustomContiguous @@ -200,6 +203,7 @@ public func run_UTF16Decode_InitFromCustom_noncontiguous(_ N: Int) { blackHole(String(decoding: input, as: UTF16.self)) } } + @inline(never) public func run_UTF16Decode_InitFromCustom_noncontiguous_ascii(_ N: Int) { let input = asciiCustomNoncontiguous @@ -207,4 +211,3 @@ public func run_UTF16Decode_InitFromCustom_noncontiguous_ascii(_ N: Int) { blackHole(String(decoding: input, as: UTF16.self)) } } - From 71e828875788a8214c2456181afa19a04d845a87 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Tue, 14 Feb 2023 12:50:07 +0200 Subject: [PATCH 3/8] Fix compile error in benchmark/single-source/UTF16Decode.swift --- benchmark/single-source/UTF16Decode.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index eefbc0d8371c4..0ed3aec8ed23b 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -13,7 +13,7 @@ import TestsUtils import Foundation -public let UTF16Decode = [ +public let benchmarks = [ BenchmarkInfo( name: "UTF16Decode", runFunction: run_UTF16Decode, From 66f5634a5f82c5d40e3710988bfd643780bf759b Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Tue, 14 Feb 2023 16:21:42 +0200 Subject: [PATCH 4/8] Rename test to follow convension --- benchmark/single-source/UTF16Decode.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index 0ed3aec8ed23b..9757e474aa3b9 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -19,39 +19,39 @@ public let benchmarks = [ runFunction: run_UTF16Decode, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromCustom_contiguous", + name: "UTF16Decode.initFromCustom.cont", runFunction: run_UTF16Decode_InitFromCustom_contiguous, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromCustom_contiguous_ascii", + name: "UTF16Decode.initFromCustom.cont.ascii", runFunction: run_UTF16Decode_InitFromCustom_contiguous_ascii, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromCustom_noncontiguous", + name: "UTF16Decode.initFromCustom.noncont", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromCustom_noncontiguous_ascii", + name: "UTF16Decode.initFromCustom.noncont.ascii", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous_ascii, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromData", + name: "UTF16Decode.initFromData", runFunction: run_UTF16Decode_InitFromData, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitDecoding", + name: "UTF16Decode.initDecoding", runFunction: run_UTF16Decode_InitDecoding, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromData_ascii", + name: "UTF16Decode.initFromData.ascii", runFunction: run_UTF16Decode_InitFromData_ascii, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitDecoding_ascii", + name: "UTF16Decode.initDecoding.ascii", runFunction: run_UTF16Decode_InitDecoding_ascii, tags: [.validation, .api, .String]), BenchmarkInfo( - name: "UTF16Decode_InitFromData_ascii_as_ascii", + name: "UTF16Decode.initFromData.asciiAsAscii", runFunction: run_UTF16Decode_InitFromData_ascii_as_ascii, tags: [.validation, .api, .String]), ] From 4682d1e6c29ade23b19e2f6ede479fe109cc2fa2 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Tue, 14 Feb 2023 16:43:51 +0200 Subject: [PATCH 5/8] Reduce benchmark execution time --- benchmark/single-source/UTF16Decode.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index 9757e474aa3b9..ebbfe5c14441d 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -110,7 +110,7 @@ public func run_UTF16Decode_InitFromData(_ N: Int) { @inline(never) public func run_UTF16Decode_InitDecoding(_ N: Int) { let input: [CodeUnit] = allStringsCodeUnits - for _ in 0..<200*N { + for _ in 0..<2*N { blackHole(String(decoding: input, as: UTF16.self)) } } @@ -118,7 +118,7 @@ public func run_UTF16Decode_InitDecoding(_ N: Int) { @inline(never) public func run_UTF16Decode_InitFromData_ascii(_ N: Int) { let input = asciiData - for _ in 0..<1_000*N { + for _ in 0..<100*N { blackHole(String(data: input, encoding: .utf16)) } } @@ -126,7 +126,7 @@ public func run_UTF16Decode_InitFromData_ascii(_ N: Int) { @inline(never) public func run_UTF16Decode_InitDecoding_ascii(_ N: Int) { let input = asciiCodeUnits - for _ in 0..<1_000*N { + for _ in 0.. Date: Tue, 14 Feb 2023 20:56:33 +0200 Subject: [PATCH 6/8] Move setup out of benchmark functions --- benchmark/single-source/UTF16Decode.swift | 31 ++++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index ebbfe5c14441d..ad0a2bdc63f8a 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -79,8 +79,6 @@ let allStringsData: Data = allStringsCodeUnits.withUnsafeBytes { Data($0) } @inline(never) public func run_UTF16Decode(_ N: Int) { - let strings = allStrings - func isEmpty(_ result: UnicodeDecodingResult) -> Bool { switch result { case .emptyInput: @@ -91,7 +89,7 @@ public func run_UTF16Decode(_ N: Int) { } for _ in 1...200*N { - for string in strings { + for string in allStrings { var it = string.makeIterator() var utf16 = UTF16() while !isEmpty(utf16.decode(&it)) { } @@ -101,41 +99,36 @@ public func run_UTF16Decode(_ N: Int) { @inline(never) public func run_UTF16Decode_InitFromData(_ N: Int) { - let input = allStringsData for _ in 0..<200*N { - blackHole(String(data: input, encoding: .utf16)) + blackHole(String(data: allStringsData, encoding: .utf16)) } } @inline(never) public func run_UTF16Decode_InitDecoding(_ N: Int) { - let input: [CodeUnit] = allStringsCodeUnits for _ in 0..<2*N { - blackHole(String(decoding: input, as: UTF16.self)) + blackHole(String(decoding: allStringsCodeUnits, as: UTF16.self)) } } @inline(never) public func run_UTF16Decode_InitFromData_ascii(_ N: Int) { - let input = asciiData for _ in 0..<100*N { - blackHole(String(data: input, encoding: .utf16)) + blackHole(String(data: asciiData, encoding: .utf16)) } } @inline(never) public func run_UTF16Decode_InitDecoding_ascii(_ N: Int) { - let input = asciiCodeUnits for _ in 0.. Date: Wed, 15 Feb 2023 12:32:30 +0200 Subject: [PATCH 7/8] Skip some benchmarks --- benchmark/single-source/UTF16Decode.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index ad0a2bdc63f8a..d3f4d3df4a9be 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -25,7 +25,7 @@ public let benchmarks = [ BenchmarkInfo( name: "UTF16Decode.initFromCustom.cont.ascii", runFunction: run_UTF16Decode_InitFromCustom_contiguous_ascii, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String, .skip]), BenchmarkInfo( name: "UTF16Decode.initFromCustom.noncont", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous, @@ -33,7 +33,7 @@ public let benchmarks = [ BenchmarkInfo( name: "UTF16Decode.initFromCustom.noncont.ascii", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous_ascii, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String, .skip]), BenchmarkInfo( name: "UTF16Decode.initFromData", runFunction: run_UTF16Decode_InitFromData, @@ -45,15 +45,15 @@ public let benchmarks = [ BenchmarkInfo( name: "UTF16Decode.initFromData.ascii", runFunction: run_UTF16Decode_InitFromData_ascii, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String, .skip]), BenchmarkInfo( name: "UTF16Decode.initDecoding.ascii", runFunction: run_UTF16Decode_InitDecoding_ascii, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String, .skip]), BenchmarkInfo( name: "UTF16Decode.initFromData.asciiAsAscii", runFunction: run_UTF16Decode_InitFromData_ascii_as_ascii, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String, .skip]), ] typealias CodeUnit = UInt16 From e0966d64ab1b85b82f03e9926afc442050f6e682 Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Wed, 22 Feb 2023 01:28:18 +0200 Subject: [PATCH 8/8] Add setUp func --- benchmark/single-source/UTF16Decode.swift | 41 +++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/benchmark/single-source/UTF16Decode.swift b/benchmark/single-source/UTF16Decode.swift index d3f4d3df4a9be..32179225f99d2 100644 --- a/benchmark/single-source/UTF16Decode.swift +++ b/benchmark/single-source/UTF16Decode.swift @@ -17,43 +17,53 @@ public let benchmarks = [ BenchmarkInfo( name: "UTF16Decode", runFunction: run_UTF16Decode, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromCustom.cont", runFunction: run_UTF16Decode_InitFromCustom_contiguous, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromCustom.cont.ascii", runFunction: run_UTF16Decode_InitFromCustom_contiguous_ascii, - tags: [.validation, .api, .String, .skip]), + tags: [.validation, .api, .String, .skip], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromCustom.noncont", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromCustom.noncont.ascii", runFunction: run_UTF16Decode_InitFromCustom_noncontiguous_ascii, - tags: [.validation, .api, .String, .skip]), + tags: [.validation, .api, .String, .skip], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromData", runFunction: run_UTF16Decode_InitFromData, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initDecoding", runFunction: run_UTF16Decode_InitDecoding, - tags: [.validation, .api, .String]), + tags: [.validation, .api, .String], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromData.ascii", runFunction: run_UTF16Decode_InitFromData_ascii, - tags: [.validation, .api, .String, .skip]), + tags: [.validation, .api, .String, .skip], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initDecoding.ascii", runFunction: run_UTF16Decode_InitDecoding_ascii, - tags: [.validation, .api, .String, .skip]), + tags: [.validation, .api, .String, .skip], + setUpFunction: setUp), BenchmarkInfo( name: "UTF16Decode.initFromData.asciiAsAscii", runFunction: run_UTF16Decode_InitFromData_ascii_as_ascii, - tags: [.validation, .api, .String, .skip]), + tags: [.validation, .api, .String, .skip], + setUpFunction: setUp), ] typealias CodeUnit = UInt16 @@ -76,6 +86,17 @@ let allStrings: [[CodeUnit]] = [ascii, russian, japanese, emoji].map { Array($0. let allStringsCodeUnits: [CodeUnit] = Array(allStrings.joined()) let allStringsData: Data = allStringsCodeUnits.withUnsafeBytes { Data($0) } +func setUp() { + blackHole(asciiCodeUnits) + blackHole(asciiData) + blackHole(allStrings) + blackHole(allStringsCodeUnits) + blackHole(allStringsData) + blackHole(allStringsCustomContiguous) + blackHole(asciiCustomContiguous) + blackHole(allStringsCustomNoncontiguous) + blackHole(asciiCustomNoncontiguous) +} @inline(never) public func run_UTF16Decode(_ N: Int) {