File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Sources/AlgorithmsBenchmark Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -18,16 +18,26 @@ let package = Package(
18
18
. library(
19
19
name: " Algorithms " ,
20
20
targets: [ " Algorithms " ] ) ,
21
+ . executable( name: " algorithms-benchmark " ,
22
+ targets: [ " AlgorithmsBenchmark " ] ) ,
21
23
] ,
22
24
dependencies: [
23
25
. 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 " ) ,
24
27
] ,
25
28
targets: [
26
29
. target(
27
30
name: " Algorithms " ,
28
31
dependencies: [
29
32
. product( name: " RealModule " , package : " swift-numerics " ) ,
30
33
] ) ,
34
+ . target(
35
+ name: " AlgorithmsBenchmark " ,
36
+ dependencies: [
37
+ " Algorithms " ,
38
+ . product( name: " CollectionsBenchmark " ,
39
+ package : " swift-collections-benchmark " ) ,
40
+ ] ) ,
31
41
. testTarget(
32
42
name: " SwiftAlgorithmsTests " ,
33
43
dependencies: [ " Algorithms " ] ) ,
Original file line number Diff line number Diff line change
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 ( ) )
You can’t perform that action at this time.
0 commit comments