Skip to content

Commit 1d2643b

Browse files
committed
Support performance testing with automatic bridging disabled.
1 parent 9674182 commit 1d2643b

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include(AddSwiftBenchmarkSuite)
1717
set(SWIFT_BENCH_MODULES
1818
single-source/unit-tests/ObjectiveCBridging
1919
single-source/unit-tests/ObjectiveCBridgingStubs
20+
single-source/unit-tests/ObjectiveCNoBridgingStubs
2021
single-source/unit-tests/StackPromo
2122
single-source/Ackermann
2223
single-source/AngryPhonebook

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ function (swift_benchmark_compile_archopts)
157157
get_filename_component(module_name "${module_name_path}" NAME)
158158

159159
if(module_name)
160+
set(extra_options "")
161+
# For this file we disable automatic bridging between Foundation and swift.
162+
if("${module_name}" STREQUAL "ObjectiveCNoBridgingStubs")
163+
set(extra_options "-Xfrontend"
164+
"-disable-swift-bridge-attr")
165+
endif()
160166
set(objfile "${objdir}/${module_name}.o")
161167
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
162168
set(source "${srcdir}/${module_name_path}.swift")
@@ -168,6 +174,7 @@ function (swift_benchmark_compile_archopts)
168174
"${srcdir}/${module_name_path}.swift"
169175
COMMAND "${SWIFT_EXEC}"
170176
${common_options}
177+
${extra_options}
171178
"-parse-as-library"
172179
${bench_flags}
173180
"-module-name" "${module_name}"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- ObjectiveCNoBridgingStubs.swift ----------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file is compiled with -Xfrontend -disable-swift-bridge-attr. No bridging
14+
// of swift types happens.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
import TestsUtils
19+
import Foundation
20+
import ObjectiveCTests
21+
22+
@inline(never)
23+
func testObjectiveCBridgeStubFromNSStringRef() {
24+
let b = BridgeTester()
25+
var nsString : NSString = NSString()
26+
for _ in 0 ..< 10_000 {
27+
nsString = b.testToString()
28+
}
29+
CheckResults(nsString.isEqual(to: "Default string value no tagged pointer" as NSString), "Wrong value returned")
30+
}
31+
32+
@inline(never)
33+
public func run_ObjectiveCBridgeStubFromNSStringRef(N: Int) {
34+
autoreleasepool {
35+
for _ in 0 ..< N {
36+
testObjectiveCBridgeStubFromNSStringRef()
37+
}
38+
}
39+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import NopDeinit
6565
import ObjectAllocation
6666
import ObjectiveCBridging
6767
import ObjectiveCBridgingStubs
68+
import ObjectiveCNoBridgingStubs
6869
import OpenClose
6970
import Phonebook
7071
import PolymorphicCalls
@@ -171,6 +172,7 @@ precommitTests = [
171172
"ObjectiveCBridgeStubToNSString": run_ObjectiveCBridgeStubToNSString,
172173
"ObjectiveCBridgeStubFromArrayOfNSString": run_ObjectiveCBridgeStubFromArrayOfNSString,
173174
"ObjectiveCBridgeStubToArrayOfNSString": run_ObjectiveCBridgeStubToArrayOfNSString,
175+
"ObjectiveCBridgeStubFromNSStringRef": run_ObjectiveCBridgeStubFromNSStringRef,
174176
"OpenClose": run_OpenClose,
175177
"Phonebook": run_Phonebook,
176178
"PolymorphicCalls": run_PolymorphicCalls,

0 commit comments

Comments
 (0)