Skip to content

Commit 3e718d3

Browse files
author
Ben Ng
committed
Add benchmarks for += in ArrayAppend
1 parent 3157d9e commit 3e718d3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

benchmark/single-source/ArrayAppend.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,28 @@ public func run_ArrayAppendToFromGeneric(_ N: Int) {
241241
}
242242
}
243243

244+
// Append a single element array with the += operator
245+
@inline(never)
246+
public func run_ArrayPlusEqualSingleElementCollection(_ N: Int) {
247+
for _ in 0..<N {
248+
for _ in 0..<10 {
249+
var nums = [Int]()
250+
for _ in 0..<40_000 {
251+
nums += [1]
252+
}
253+
}
254+
}
255+
}
256+
257+
// Append a five element array with the += operator
258+
@inline(never)
259+
public func run_ArrayPlusEqualFiveElementCollection(_ N: Int) {
260+
for _ in 0..<N {
261+
for _ in 0..<10 {
262+
var nums = [Int]()
263+
for _ in 0..<40_000 {
264+
nums += [1, 2, 3, 4, 5]
265+
}
266+
}
267+
}
268+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ precommitTests = [
121121
"ArrayAppendStrings": run_ArrayAppendStrings,
122122
"ArrayAppendToFromGeneric": run_ArrayAppendToFromGeneric,
123123
"ArrayAppendToGeneric": run_ArrayAppendToGeneric,
124+
"ArrayPlusEqualSingleElementCollection": run_ArrayPlusEqualSingleElementCollection,
125+
"ArrayPlusEqualFiveElementCollection": run_ArrayPlusEqualFiveElementCollection,
124126
"ArrayInClass": run_ArrayInClass,
125127
"ArrayLiteral": run_ArrayLiteral,
126128
"ArrayOfGenericPOD": run_ArrayOfGenericPOD,

0 commit comments

Comments
 (0)