Skip to content

Commit

Permalink
Add boilerplate for using swift-collection-benchmarks.
Browse files Browse the repository at this point in the history
Add baseline interspersed-results and interspersed-chart.png.

Update CONTRIBUTING.md for benchmarking instructions.
  • Loading branch information
LemonSpike committed Jul 30, 2021
1 parent 50be2c8 commit 506dd7e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ license](https://swift.org/LICENSE.txt).
Before submitting the pull request, please make sure you have tested your
changes and that they follow the Swift project [guidelines for contributing
code](https://swift.org/contributing/#contributing-code).

---

For benchmarking of particular algorithms, please use the

`algorithms-benchmark` executable target. For convenience, this target

already imports `Algorithms`.

Example usage:

`$ swift run -c release algorithms-benchmark run <name-of-results-file> --cycles 5`

`$ swift run -c release algorithms-benchmark render <name-of-results-file> <name-of-chart-file>.png`

10 changes: 10 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ let package = Package(
.library(
name: "Algorithms",
targets: ["Algorithms"]),
.executable(name: "algorithms-benchmark",
targets: ["AlgorithmsBenchmark"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-numerics", from: "0.0.1"),
.package(url: "https://github.com/apple/swift-collections-benchmark", from: "0.0.1"),
],
targets: [
.target(
name: "Algorithms",
dependencies: [
.product(name: "RealModule", package: "swift-numerics"),
]),
.target(
name: "AlgorithmsBenchmark",
dependencies: [
"Algorithms",
.product(name: "CollectionsBenchmark",
package: "swift-collections-benchmark"),
]),
.testTarget(
name: "SwiftAlgorithmsTests",
dependencies: ["Algorithms"]),
Expand Down
30 changes: 30 additions & 0 deletions Sources/AlgorithmsBenchmark/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Algorithms open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import Foundation
import Algorithms
import CollectionsBenchmark

/// Benchmarks `.intersperse` from Swift Algorithms for Array<Int> sequences.
func benchmarkInterspersed() {
var benchmark = Benchmark(title: "Interspersed Benchmark")

benchmark.addSimple(
title: "Array<Int> interspersed",
input: Array<Int>.self
) { input in
blackHole(input.interspersed(with: 9))
}

benchmark.main()
}

print(benchmarkInterspersed())
Binary file added interspersed-chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions interspersed-results
Original file line number Diff line number Diff line change
@@ -0,0 +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 comments on commit 506dd7e

Please sign in to comment.