@@ -14,7 +14,17 @@ impacting changes, and run the benchmarks again. Upon benchmark completion, the
14
14
benchmark results for the development branch will be compared to the most
15
15
recent benchmark results for ` master ` .
16
16
17
- ## Building with build-script
17
+ ## Building the Swift Benchmarks
18
+
19
+ The swift benchmark suite currently supports building with CMake and
20
+ SwiftPM. We support the following platforms respectively.
21
+
22
+ * CMake: macOS, iOS, tvOS, watchOS
23
+ * SwiftPM: macOS, linux
24
+
25
+ We describe how to build both standalone and with build-script below.
26
+
27
+ ### build-script invoking CMake
18
28
19
29
By default, Swift benchmarks for OS X are compiled during the Swift build
20
30
process. To build Swift benchmarks for additional platforms, pass the following
@@ -30,7 +40,7 @@ drivers dynamically link Swift standard library dylibs from a path
30
40
relative to their run-time location (../lib/swift) so the standard
31
41
library should be distributed alongside them.
32
42
33
- ## Building Independently
43
+ ### CMake Standalone (no build-script)
34
44
35
45
To build the Swift benchmarks using only an Xcode installation: install an
36
46
Xcode version with Swift support, install cmake 2.8.12, and ensure Xcode is
@@ -106,6 +116,56 @@ installed libraries instead, enable
106
116
This will reflect the performance of the Swift standard library
107
117
installed on the device, not the one included in the Swift root.
108
118
119
+ ### build-script using SwiftPM+LLBuild
120
+
121
+ To build the benchmarks using build-script/swiftpm, one must build both
122
+ swiftpm/llbuild as part of one's build and create a "just-built" toolchain. This
123
+ toolchain is then used by build-script to compile the benchmarks. This is
124
+ accomplished by passing to build-script the following options:
125
+
126
+ ```
127
+ swift-source$ swift/utils/build-script --swiftpm --llbuild --install-swift --install-swiftpm --install-llbuild --toolchain-benchmarks
128
+ ```
129
+
130
+ build-script will then compile the toolchain and then build the benchmarks 3
131
+ times, once for each optimization level, at the path
132
+ ` ./build/benchmarks-$PLATFORM-$ARCH/bin/Benchmark_$OPT ` :
133
+
134
+ ### Standalone SwiftPM/LLBuild
135
+
136
+ The benchmark suite can be built with swiftpm/llbuild without needing any help
137
+ from build-script by invoking swift build in the benchmark directory:
138
+
139
+ ```
140
+ swift-source/swift/benchmark$ swift build -configuration release
141
+ swift-source/swift/benchmark$ .build/release/SwiftBench
142
+ #,TEST,SAMPLES,MIN(μs),MAX(μs),MEAN(μs),SD(μs),MEDIAN(μs)
143
+ 1,Ackermann,1,169,169,169,0,169
144
+ 2,AngryPhonebook,1,2044,2044,2044,0,2044
145
+ ...
146
+ ```
147
+
148
+ ## Editing in Xcode
149
+
150
+ It is now possible to work on swiftpm benchmarks in Xcode! This is done by using
151
+ the ability swiftpm build of the benchmarks to generate an xcodeproject. This is
152
+ done by running the commands:
153
+
154
+ ```
155
+ swift-source/swift/benchmark$ swift package generate-xcodeproj
156
+ generated: ./swiftbench.xcodeproj
157
+ swift-source/swift/benchmark$ open swiftbench.xcodeproj
158
+ ```
159
+
160
+ Assuming that Xcode is installed on ones system, this will open the project in
161
+ Xcode. The benchmark binary is built by the target 'SwiftBench'.
162
+
163
+ ** NOTE: Files added to the Xcode project will not be persisted back to the
164
+ package! To add new benchmarks follow the instructions from the section below!**
165
+
166
+ ** NOTE: By default if one just builds/runs the benchmarks in Xcode, the
167
+ benchmarks will be compiled with -Onone!**
168
+
109
169
## Using the Benchmark Driver
110
170
111
171
### Usage
@@ -159,20 +219,29 @@ of some benchmarks.
159
219
160
220
## Adding New Benchmarks
161
221
162
- The harness generator supports both single and multiple file tests.
222
+ Adding a new benchmark requires some boilerplate updates. To ease this (and
223
+ document the behavior), a harness generator script is provided for both
224
+ single/multiple file tests.
163
225
164
- To add a new single file test, execute the following script with the new of the benchmark:
226
+ To add a new single file test, execute the following script with the new of the
227
+ benchmark:
165
228
166
229
```
167
230
swift-source$ ./swift/benchmark/scripts/create_benchmark.py YourTestNameHere
168
231
```
169
232
170
233
The script will automatically:
234
+
171
235
1 . Add a new Swift file (` YourTestNameHere.swift ` ), built according to
172
236
the template below, to the ` single-source ` directory.
173
237
2 . Add the filename of the new Swift file to ` CMakeLists.txt ` .
174
238
3 . Edit ` main.swift ` by importing and registering your new Swift module.
175
239
240
+ No changes are needed to the Package.swift file since the benchmark's
241
+ Package.swift is set to dynamically lookup each Swift file in ` single-source `
242
+ and translate each of those individual .swift files into individual modules. So
243
+ the new test file will be automatically found.
244
+
176
245
To add a new multiple file test:
177
246
178
247
1 . Add a new directory and files under the ` multi-source ` directory as
@@ -193,6 +262,9 @@ To add a new multiple file test:
193
262
194
263
3 . Edit ` main.swift ` . Import and register your new Swift module.
195
264
265
+ No changes are needed to the swiftpm build since it knows how to infer
266
+ multi-source libraries automatically from the library structure.
267
+
196
268
** Note:**
197
269
198
270
The benchmark harness will execute the routine referenced by
0 commit comments