Skip to content

Commit 94d94ee

Browse files
committed
[benchmark] Rehouse DistinctClassFieldAccesses
Benchmark DistinctClassFieldAccesses was added in a strange place… See https://github.com/apple/swift/pull/18892/files#r212038958 Per discussion in in swiftlang#18892 (comment) I’m moving it to the extremely similar `ArrayInClass`, while fixing its workload size (and loop pattern) to make it relatively comparable.
1 parent 5116244 commit 94d94ee

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

benchmark/single-source/ArrayInClass.swift

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import TestsUtils
14-
public let ArrayInClass = BenchmarkInfo(
15-
name: "ArrayInClass",
16-
runFunction: run_ArrayInClass,
17-
tags: [.validation, .api, .Array],
18-
setUpFunction: { ac = ArrayContainer() },
19-
tearDownFunction: { ac = nil })
14+
public let ArrayInClass = [
15+
BenchmarkInfo(
16+
name: "ArrayInClass",
17+
runFunction: run_ArrayInClass,
18+
tags: [.validation, .api, .Array],
19+
setUpFunction: { ac = ArrayContainer() },
20+
tearDownFunction: { ac = nil }),
21+
BenchmarkInfo(name: "DistinctClassFieldAccesses",
22+
runFunction: run_DistinctClassFieldAccesses,
23+
tags: [.unstable, .api, .Array],
24+
setUpFunction: { workload = ClassWithArrs(N: 100_000) },
25+
tearDownFunction: { workload = nil }),
26+
]
2027

2128
var ac: ArrayContainer!
2229

@@ -41,3 +48,38 @@ public func run_ArrayInClass(_ N: Int) {
4148
let a = ac!
4249
a.runLoop(N)
4350
}
51+
52+
class ClassWithArrs {
53+
var N: Int = 0
54+
var A: [Int]
55+
var B: [Int]
56+
57+
init(N: Int) {
58+
self.N = N
59+
60+
A = [Int](repeating: 0, count: N)
61+
B = [Int](repeating: 0, count: N)
62+
}
63+
64+
func readArr() {
65+
for i in 0..<self.N {
66+
guard A[i] == B[i] else { fatalError("") }
67+
}
68+
}
69+
70+
func writeArr() {
71+
for i in 0..<self.N {
72+
A[i] = i
73+
B[i] = i
74+
}
75+
}
76+
}
77+
78+
var workload: ClassWithArrs!
79+
80+
public func run_DistinctClassFieldAccesses(_ N: Int) {
81+
for _ in 1...N {
82+
workload.writeArr()
83+
workload.readArr()
84+
}
85+
}

benchmark/single-source/ExistentialPerformance.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import TestsUtils
1414

1515
public let ExistentialPerformance = [
16-
BenchmarkInfo(name: "DistinctClassFieldAccesses", runFunction: run_DistinctClassFieldAccesses, tags: [.unstable, .api, .Array]),
1716
BenchmarkInfo(name: "ExistentialTestArrayConditionalShift_ClassValueBuffer1", runFunction: run_ExistentialTestArrayConditionalShift_ClassValueBuffer1, tags: [.unstable, .api, .Array]),
1817
BenchmarkInfo(name: "ExistentialTestArrayConditionalShift_ClassValueBuffer2", runFunction: run_ExistentialTestArrayConditionalShift_ClassValueBuffer2, tags: [.unstable, .api, .Array]),
1918
BenchmarkInfo(name: "ExistentialTestArrayConditionalShift_ClassValueBuffer3", runFunction: run_ExistentialTestArrayConditionalShift_ClassValueBuffer3, tags: [.unstable, .api, .Array]),
@@ -115,44 +114,6 @@ public let ExistentialPerformance = [
115114
BenchmarkInfo(name: "ExistentialTestTwoMethodCalls_IntValueBuffer4", runFunction: run_ExistentialTestTwoMethodCalls_IntValueBuffer4, tags: [.unstable]),
116115
]
117116

118-
class ClassWithArrs {
119-
var N: Int = 0
120-
var A: [Int]
121-
var B: [Int]
122-
123-
init(N: Int) {
124-
self.N = N
125-
126-
A = [Int](repeating: 0, count: N)
127-
B = [Int](repeating: 0, count: N)
128-
}
129-
130-
func readArr() {
131-
for i in 0..<self.N {
132-
for j in 0..<i {
133-
let _ = A[j]
134-
let _ = B[j]
135-
}
136-
}
137-
}
138-
139-
func writeArr() {
140-
for i in 0..<self.N {
141-
A[i] = i
142-
B[i] = i
143-
}
144-
}
145-
}
146-
147-
let workload = ClassWithArrs(N: 100)
148-
149-
public func run_DistinctClassFieldAccesses(_ N: Int) {
150-
for _ in 1...N {
151-
workload.writeArr()
152-
workload.readArr()
153-
}
154-
}
155-
156117
protocol Existential {
157118
init()
158119
func doIt() -> Bool

0 commit comments

Comments
 (0)