Skip to content

Support performance testing with automatic bridging disabled. #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include(AddSwiftBenchmarkSuite)
set(SWIFT_BENCH_MODULES
single-source/unit-tests/ObjectiveCBridging
single-source/unit-tests/ObjectiveCBridgingStubs
single-source/unit-tests/ObjectiveCNoBridgingStubs
single-source/unit-tests/StackPromo
single-source/Ackermann
single-source/AngryPhonebook
Expand Down
7 changes: 7 additions & 0 deletions benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ function (swift_benchmark_compile_archopts)
get_filename_component(module_name "${module_name_path}" NAME)

if(module_name)
set(extra_options "")
# For this file we disable automatic bridging between Foundation and swift.
if("${module_name}" STREQUAL "ObjectiveCNoBridgingStubs")
set(extra_options "-Xfrontend"
"-disable-swift-bridge-attr")
endif()
set(objfile "${objdir}/${module_name}.o")
set(swiftmodule "${objdir}/${module_name}.swiftmodule")
set(source "${srcdir}/${module_name_path}.swift")
Expand All @@ -168,6 +174,7 @@ function (swift_benchmark_compile_archopts)
"${srcdir}/${module_name_path}.swift"
COMMAND "${SWIFT_EXEC}"
${common_options}
${extra_options}
"-parse-as-library"
${bench_flags}
"-module-name" "${module_name}"
Expand Down
39 changes: 39 additions & 0 deletions benchmark/single-source/unit-tests/ObjectiveCNoBridgingStubs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===--- ObjectiveCNoBridgingStubs.swift ----------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file is compiled with -Xfrontend -disable-swift-bridge-attr. No bridging
// of swift types happens.
//
//===----------------------------------------------------------------------===//

import TestsUtils
import Foundation
import ObjectiveCTests

@inline(never)
func testObjectiveCBridgeStubFromNSStringRef() {
let b = BridgeTester()
var nsString : NSString = NSString()
for _ in 0 ..< 10_000 {
nsString = b.testToString()
}
CheckResults(nsString.isEqual(to: "Default string value no tagged pointer" as NSString), "Wrong value returned")
}

@inline(never)
public func run_ObjectiveCBridgeStubFromNSStringRef(N: Int) {
autoreleasepool {
for _ in 0 ..< N {
testObjectiveCBridgeStubFromNSStringRef()
}
}
}
2 changes: 2 additions & 0 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import NopDeinit
import ObjectAllocation
import ObjectiveCBridging
import ObjectiveCBridgingStubs
import ObjectiveCNoBridgingStubs
import OpenClose
import Phonebook
import PolymorphicCalls
Expand Down Expand Up @@ -171,6 +172,7 @@ precommitTests = [
"ObjectiveCBridgeStubToNSString": run_ObjectiveCBridgeStubToNSString,
"ObjectiveCBridgeStubFromArrayOfNSString": run_ObjectiveCBridgeStubFromArrayOfNSString,
"ObjectiveCBridgeStubToArrayOfNSString": run_ObjectiveCBridgeStubToArrayOfNSString,
"ObjectiveCBridgeStubFromNSStringRef": run_ObjectiveCBridgeStubFromNSStringRef,
"OpenClose": run_OpenClose,
"Phonebook": run_Phonebook,
"PolymorphicCalls": run_PolymorphicCalls,
Expand Down