Skip to content

Commit 5909a0f

Browse files
committed
Add boilerplate for using swift-collection-benchmarks.
1 parent 50be2c8 commit 5909a0f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Package.swift

Lines changed: 10 additions & 0 deletions
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"]),
Lines changed: 30 additions & 0 deletions
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: "Intersperse 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())

0 commit comments

Comments
 (0)