Skip to content

Commit 5bb8453

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 7869077 + 54d00ab commit 5bb8453

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

benchmark/README.md

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ impacting changes, and run the benchmarks again. Upon benchmark completion, the
1414
benchmark results for the development branch will be compared to the most
1515
recent benchmark results for `master`.
1616

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
1828

1929
By default, Swift benchmarks for OS X are compiled during the Swift build
2030
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
3040
relative to their run-time location (../lib/swift) so the standard
3141
library should be distributed alongside them.
3242

33-
## Building Independently
43+
### CMake Standalone (no build-script)
3444

3545
To build the Swift benchmarks using only an Xcode installation: install an
3646
Xcode version with Swift support, install cmake 2.8.12, and ensure Xcode is
@@ -106,6 +116,56 @@ installed libraries instead, enable
106116
This will reflect the performance of the Swift standard library
107117
installed on the device, not the one included in the Swift root.
108118

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+
109169
## Using the Benchmark Driver
110170

111171
### Usage
@@ -159,20 +219,29 @@ of some benchmarks.
159219

160220
## Adding New Benchmarks
161221

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.
163225

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:
165228

166229
```
167230
swift-source$ ./swift/benchmark/scripts/create_benchmark.py YourTestNameHere
168231
```
169232

170233
The script will automatically:
234+
171235
1. Add a new Swift file (`YourTestNameHere.swift`), built according to
172236
the template below, to the `single-source` directory.
173237
2. Add the filename of the new Swift file to `CMakeLists.txt`.
174238
3. Edit `main.swift` by importing and registering your new Swift module.
175239

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+
176245
To add a new multiple file test:
177246

178247
1. Add a new directory and files under the `multi-source` directory as
@@ -193,6 +262,9 @@ To add a new multiple file test:
193262

194263
3. Edit `main.swift`. Import and register your new Swift module.
195264

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+
196268
**Note:**
197269

198270
The benchmark harness will execute the routine referenced by

0 commit comments

Comments
 (0)