Skip to content

Commit 506dd7e

Browse files
committed
Add boilerplate for using swift-collection-benchmarks.
Add baseline interspersed-results and interspersed-chart.png. Update CONTRIBUTING.md for benchmarking instructions.
1 parent 50be2c8 commit 506dd7e

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

CONTRIBUTING.md

+15
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@ license](https://swift.org/LICENSE.txt).
88
Before submitting the pull request, please make sure you have tested your
99
changes and that they follow the Swift project [guidelines for contributing
1010
code](https://swift.org/contributing/#contributing-code).
11+
12+
---
13+
14+
For benchmarking of particular algorithms, please use the
15+
16+
`algorithms-benchmark` executable target. For convenience, this target
17+
18+
already imports `Algorithms`.
19+
20+
Example usage:
21+
22+
`$ swift run -c release algorithms-benchmark run <name-of-results-file> --cycles 5`
23+
24+
`$ swift run -c release algorithms-benchmark render <name-of-results-file> <name-of-chart-file>.png`
25+

Package.swift

+10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ let package = Package(
1818
.library(
1919
name: "Algorithms",
2020
targets: ["Algorithms"]),
21+
.executable(name: "algorithms-benchmark",
22+
targets: ["AlgorithmsBenchmark"]),
2123
],
2224
dependencies: [
2325
.package(url: "https://github.com/apple/swift-numerics", from: "0.0.1"),
26+
.package(url: "https://github.com/apple/swift-collections-benchmark", from: "0.0.1"),
2427
],
2528
targets: [
2629
.target(
2730
name: "Algorithms",
2831
dependencies: [
2932
.product(name: "RealModule", package: "swift-numerics"),
3033
]),
34+
.target(
35+
name: "AlgorithmsBenchmark",
36+
dependencies: [
37+
"Algorithms",
38+
.product(name: "CollectionsBenchmark",
39+
package: "swift-collections-benchmark"),
40+
]),
3141
.testTarget(
3242
name: "SwiftAlgorithmsTests",
3343
dependencies: ["Algorithms"]),
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Algorithms open source project
4+
//
5+
// Copyright (c) 2021 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+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
import Foundation
13+
import Algorithms
14+
import CollectionsBenchmark
15+
16+
/// Benchmarks `.intersperse` from Swift Algorithms for Array<Int> sequences.
17+
func benchmarkInterspersed() {
18+
var benchmark = Benchmark(title: "Interspersed Benchmark")
19+
20+
benchmark.addSimple(
21+
title: "Array<Int> interspersed",
22+
input: Array<Int>.self
23+
) { input in
24+
blackHole(input.interspersed(with: 9))
25+
}
26+
27+
benchmark.main()
28+
}
29+
30+
print(benchmarkInterspersed())

interspersed-chart.png

143 KB
Loading

interspersed-results

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"tasks":[{"title":"Array<Int> interspersed","results":{"57344":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"786432":[1.67e-09,1.67e-09,1.8636363636363636e-09,2.0800000000000003e-09,2.0800000000000003e-09],"1280":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"48":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"458752":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"56":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"98304":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"64":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"131072":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"20480":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"80":[1.67e-09,1.75e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"1":[1.8260869565217392e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"2":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"768":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"3":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"4":[1.8260869565217392e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"320":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"393216":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"5":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"6":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"10240":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"7":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"24576":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"10":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"8":[1.67e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"896":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"163840":[1.67e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"917504":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"3584":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.5000000000000001e-09],"40960":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"524288":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"1536":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.09e-09],"12":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"2560":[1.8260869565217392e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"65536":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"229376":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"327680":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"512":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"20":[1.67e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"81920":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"655360":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.5000000000000001e-09],"14336":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"14":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"96":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"12288":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"128":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"49152":[1.67e-09,1.67e-09,1.67e-09,1.67e-09,2.0800000000000003e-09],"16":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"640":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"192":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"24":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"4096":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"32":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"2048":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"256":[1.6600000000000001e-09,1.67e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09],"3072":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.09e-09,2.09e-09],"1792":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"40":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"28672":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"1024":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"262144":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"1048576":[1.6600000000000001e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"7168":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"8192":[1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"28":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"32768":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"6144":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"384":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"160":[1.6600000000000001e-09,1.67e-09,1.67e-09,2.0800000000000003e-09,2.0800000000000003e-09],"5120":[1.8260869565217392e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"448":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"114688":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"16384":[1.6600000000000001e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.09e-09],"112":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"224":[2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09],"196608":[1.75e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09,2.0800000000000003e-09]}}]}

0 commit comments

Comments
 (0)