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
196
196
single-source/WordCount
197
197
single-source/XorLoop
198
198
cxx-source/CreateObjects
199
+ cxx-source/ReadAccessor
199
200
)
200
201
201
202
set (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 {
2
2
header "CreateObjects.h"
3
3
requires cplusplus
4
4
}
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
152
152
import RangeIteration
153
153
import RangeOverlaps
154
154
import RangeReplaceableCollectionPlusDefault
155
+ import ReadAccessor
155
156
import RecursiveOwnedParameter
156
157
import ReduceInto
157
158
import RemoveWhere
@@ -332,6 +333,7 @@ register(RangeAssignment.benchmarks)
332
333
register ( RangeIteration . benchmarks)
333
334
register ( RangeOverlaps . benchmarks)
334
335
register ( RangeReplaceableCollectionPlusDefault . benchmarks)
336
+ register ( ReadAccessor . benchmarks)
335
337
register ( RecursiveOwnedParameter . benchmarks)
336
338
register ( ReduceInto . benchmarks)
337
339
register ( RemoveWhere . benchmarks)
You can’t perform that action at this time.
0 commit comments