File tree Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ set(SWIFT_BENCH_MODULES
196196 single-source /WordCount
197197 single-source /XorLoop
198198 cxx-source /CreateObjects
199+ cxx-source /ReadAccessor
199200)
200201
201202set (SWIFT_MULTISOURCE_SWIFT_BENCHES
Original file line number Diff line number Diff line change 1+ // Subscripts.swift - Very brief description
2+ //
3+ // This source file is part of the Swift.org open source project
4+ //
5+ // Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+ // Licensed under Apache License v2.0 with Runtime Library Exception
7+ //
8+ // See https://swift.org/LICENSE.txt for license information
9+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+ //
11+ // -----------------------------------------------------------------------------
12+ ///
13+ /// This is a simple test that reads a non trivial C++ struct using an imported
14+ /// subscript thousands of times.
15+ ///
16+ // -----------------------------------------------------------------------------
17+
18+ import TestsUtils
19+ import CxxSubscripts
20+
21+ var vec : TwoDimensionalVector ?
22+
23+ public let benchmarks = [
24+ BenchmarkInfo (
25+ name: " ReadAccessor " ,
26+ runFunction: run_ReadAccessor,
27+ tags: [ . validation, . bridging] ,
28+ setUpFunction: {
29+ vec = initVector ( )
30+ } )
31+ ]
32+
33+ @inline ( never)
34+ public func run_ReadAccessor( _ N: Int ) {
35+ for i in 0 ... N {
36+ for j in 0 ..< 100 {
37+ #if os(Linux)
38+ let row = vec![ UInt ( j) ] ;
39+ #else
40+ let row = vec![ j] ;
41+ #endif
42+ for k in 0 ..< 1_000 {
43+ #if os(Linux)
44+ let element = row [ UInt ( k) ] ;
45+ #else
46+ let element = row [ k] ;
47+ #endif
48+ blackHole ( element)
49+ }
50+ }
51+ }
52+ }
Original file line number Diff line number Diff line change 1+ #ifndef BENCHMARK_SUBSCRIPTS_H
2+ #define BENCHMARK_SUBSCRIPTS_H
3+ #include < vector>
4+
5+ using TwoDimensionalVector = std::vector<std::vector<int >>;
6+
7+ inline TwoDimensionalVector initVector () { return {100 , std::vector<int >{1000 , 0 }}; }
8+
9+ #endif
10+
Original file line number Diff line number Diff line change @@ -2,3 +2,8 @@ module CxxCreateObjects {
22 header "CreateObjects.h"
33 requires cplusplus
44}
5+
6+ module CxxSubscripts {
7+ header "Subscripts.h"
8+ requires cplusplus
9+ }
Original file line number Diff line number Diff line change @@ -152,6 +152,7 @@ import RangeAssignment
152152import RangeIteration
153153import RangeOverlaps
154154import RangeReplaceableCollectionPlusDefault
155+ import ReadAccessor
155156import RecursiveOwnedParameter
156157import ReduceInto
157158import RemoveWhere
@@ -332,6 +333,7 @@ register(RangeAssignment.benchmarks)
332333register ( RangeIteration . benchmarks)
333334register ( RangeOverlaps . benchmarks)
334335register ( RangeReplaceableCollectionPlusDefault . benchmarks)
336+ register ( ReadAccessor . benchmarks)
335337register ( RecursiveOwnedParameter . benchmarks)
336338register ( ReduceInto . benchmarks)
337339register ( RemoveWhere . benchmarks)
You can’t perform that action at this time.
0 commit comments