Skip to content

Commit 8876c24

Browse files
committed
benchmarks: add some blackHole calls to prevent the optimizer removing important parts of a benchmark
1 parent 1a7bee5 commit 8876c24

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

benchmark/single-source/ArrayOfGenericPOD.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RefArray<T> {
4040
// elements should be a nop.
4141
@inline(never)
4242
func genEnumArray() {
43-
_ = RefArray<Int?>(3)
43+
blackHole(RefArray<Int?>(3))
4444
// should be a nop
4545
}
4646

@@ -53,7 +53,7 @@ struct S<T> {
5353
}
5454
@inline(never)
5555
func genStructArray() {
56-
_ = RefArray<S<Int>>(S(x:3, y:4))
56+
blackHole(RefArray<S<Int>>(S(x:3, y:4)))
5757
// should be a nop
5858
}
5959

benchmark/single-source/ArrayOfGenericRef.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GenericRef<T> : Constructible {
4747
// Reference to a POD class.
4848
@inline(never)
4949
func genPODRefArray() {
50-
_ = ConstructibleArray<GenericRef<Int>>(3)
50+
blackHole(ConstructibleArray<GenericRef<Int>>(3))
5151
// should be a nop
5252
}
5353

@@ -57,7 +57,7 @@ class Dummy {}
5757
@inline(never)
5858
func genCommonRefArray() {
5959
let d = Dummy()
60-
_ = ConstructibleArray<GenericRef<Dummy>>(d)
60+
blackHole(ConstructibleArray<GenericRef<Dummy>>(d))
6161
// should be a nop
6262
}
6363

@@ -74,7 +74,7 @@ class RefArray<T> {
7474
@inline(never)
7575
func genRefEnumArray() {
7676
let d = Dummy()
77-
_ = RefArray<Dummy?>(d)
77+
blackHole(RefArray<Dummy?>(d))
7878
// should be a nop
7979
}
8080

@@ -88,7 +88,7 @@ struct GenericVal<T> : Constructible {
8888
@inline(never)
8989
func genRefStructArray() {
9090
let d = Dummy()
91-
_ = ConstructibleArray<GenericVal<Dummy>>(d)
91+
blackHole(ConstructibleArray<GenericVal<Dummy>>(d))
9292
// should be a nop
9393
}
9494

benchmark/single-source/ArrayOfPOD.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class RefArray<T> {
3333

3434
@inline(never)
3535
func genIntArray() {
36-
_ = RefArray<Int>(3, count:200_000)
36+
blackHole(RefArray<Int>(3, count:200_000))
3737
// should be a nop
3838
}
3939

@@ -45,7 +45,7 @@ enum PODEnum {
4545

4646
@inline(never)
4747
func genEnumArray() {
48-
_ = RefArray<PODEnum>(PODEnum.Some(3))
48+
blackHole(RefArray<PODEnum>(PODEnum.Some(3)))
4949
// should be a nop
5050
}
5151

@@ -55,7 +55,7 @@ struct S {
5555
}
5656
@inline(never)
5757
func genStructArray() {
58-
_ = RefArray<S>(S(x:3, y:4))
58+
blackHole(RefArray<S>(S(x:3, y:4)))
5959
// should be a nop
6060
}
6161

benchmark/single-source/ArrayOfRef.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class POD : Constructible {
4848

4949
@inline(never)
5050
func genPODRefArray() {
51-
_ = ConstructibleArray<POD>(3)
51+
blackHole(ConstructibleArray<POD>(3))
5252
// should be a nop
5353
}
5454

@@ -64,7 +64,7 @@ class CommonRef : Constructible {
6464
@inline(never)
6565
func genCommonRefArray() {
6666
let d = Dummy()
67-
_ = ConstructibleArray<CommonRef>(d)
67+
blackHole(ConstructibleArray<CommonRef>(d))
6868
// should be a nop
6969
}
7070

@@ -85,7 +85,7 @@ class RefArray<T> {
8585
@inline(never)
8686
func genRefEnumArray() {
8787
let e = RefEnum.Some(Dummy())
88-
_ = RefArray<RefEnum>(e)
88+
blackHole(RefArray<RefEnum>(e))
8989
// should be a nop
9090
}
9191

@@ -99,7 +99,7 @@ struct S : Constructible {
9999
@inline(never)
100100
func genRefStructArray() {
101101
let d = Dummy()
102-
_ = ConstructibleArray<S>(d)
102+
blackHole(ConstructibleArray<S>(d))
103103
// should be a nop
104104
}
105105

benchmark/single-source/RemoveWhere.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ let ints = Array(0..<n)
115115
let str = String(repeating: "A very long ASCII string.", count: n/50)
116116

117117
func buildWorkload() {
118-
_ = strings.count
119-
_ = ints.count
120-
_ = str.count
118+
blackHole(strings)
119+
blackHole(ints)
120+
blackHole(str)
121121
}
122122

123123

benchmark/single-source/SequenceAlgos.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ let y = AnySequence(0..<n)
6464
let s = sequence(first: 0, next: { $0 < n&-1 ? $0&+1 : nil})
6565

6666
func buildWorkload() {
67-
_ = l.makeIterator()
68-
_ = c.makeIterator()
69-
_ = a.makeIterator()
70-
_ = y.makeIterator()
71-
_ = s.makeIterator()
67+
blackHole(l.makeIterator())
68+
blackHole(c.makeIterator())
69+
blackHole(a.makeIterator())
70+
blackHole(y.makeIterator())
71+
blackHole(s.makeIterator())
7272
}
7373

7474
func benchmarkEquatableSequenceAlgos<S: Sequence>(s: S, n: Int) where S.Element == Int, S: Equatable {

0 commit comments

Comments
 (0)