Skip to content

Commit 994c04f

Browse files
committed
benchmarks: add another benchmark for appending multiple array elements.
In contrast to the other similar benchmarks, this benchmark starts with a new array each iteration.
1 parent 7914e09 commit 994c04f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

benchmark/single-source/ArrayAppend.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ public func run_ArrayPlusEqualFiveElementCollection(_ N: Int) {
267267
}
268268
}
269269

270+
@inline(never)
271+
public func appendThreeElements(_ a: inout [Int]) {
272+
a += [1, 2, 3]
273+
}
274+
275+
@inline(never)
276+
public func run_ArrayPlusEqualThreeElements(_ N: Int) {
277+
for _ in 0..<(10_000 * N) {
278+
var a: [Int] = []
279+
appendThreeElements(&a)
280+
}
281+
}
282+
270283
// Append the utf8 elements of an ascii string to a [UInt8]
271284
@inline(never)
272285
public func run_ArrayAppendAscii(_ N: Int) {

benchmark/utils/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ addPrecommitTest("ArrayOfRef", run_ArrayOfRef)
167167
addPrecommitTest("ArrayPlusEqualArrayOfInt", run_ArrayPlusEqualArrayOfInt)
168168
addPrecommitTest("ArrayPlusEqualFiveElementCollection", run_ArrayPlusEqualFiveElementCollection)
169169
addPrecommitTest("ArrayPlusEqualSingleElementCollection", run_ArrayPlusEqualSingleElementCollection)
170+
addPrecommitTest("ArrayPlusEqualThreeElements", run_ArrayPlusEqualThreeElements)
170171
addPrecommitTest("ArraySubscript", run_ArraySubscript)
171172
addPrecommitTest("ArrayValueProp", run_ArrayValueProp)
172173
addPrecommitTest("ArrayValueProp2", run_ArrayValueProp2)

0 commit comments

Comments
 (0)