Skip to content

Commit c6dc0b0

Browse files
committed
Add Array benchmarks
1 parent 4a55f70 commit c6dc0b0

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

benchmark/single-source/DropLast.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,18 @@ public func run_DropLastAnySequence(_ N: Int) {
6969
}
7070
}
7171
}
72+
73+
@inline(never)
74+
public func run_DropLastArray(_ N: Int) {
75+
let s = Array(0 ..< sequenceCount)
76+
for _ in 1...20*N {
77+
for _ in 1...reps {
78+
var result = 0
79+
for element in s.dropLast(dropCount) {
80+
result += element
81+
}
82+
CheckResults(result == sumCount,
83+
"IncorrectResults in DropLastArray: \(result) != \(sumCount)")
84+
}
85+
}
86+
}

benchmark/single-source/Suffix.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,17 @@ public func run_SuffixAnySequence(_ N: Int) {
6969
}
7070
}
7171

72+
@inline(never)
73+
public func run_SuffixArray(_ N: Int) {
74+
let s = Array(0 ..< sequenceCount)
75+
for _ in 1...20*N {
76+
for _ in 1...reps {
77+
var result = 0
78+
for element in s.suffix(suffixCount) {
79+
result += element
80+
}
81+
CheckResults(result == sumCount,
82+
"IncorrectResults in SuffixArray: \(result) != \(sumCount)")
83+
}
84+
}
85+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ precommitTests = [
164164
"DictionarySwap": run_DictionarySwap,
165165
"DictionarySwapOfObjects": run_DictionarySwapOfObjects,
166166
"DropLastAnySequence": run_DropLastAnySequence,
167+
"DropLastArray": run_DropLastArray,
167168
"DropLastCountableRange": run_DropLastCountableRange,
168169
"DropLastSequence": run_DropLastSequence,
169170
"ErrorHandling": run_ErrorHandling,
@@ -279,6 +280,7 @@ precommitTests = [
279280
"StringWalk": run_StringWalk,
280281
"StringWithCString": run_StringWithCString,
281282
"SuffixAnySequence": run_SuffixAnySequence,
283+
"SuffixArray": run_SuffixArray,
282284
"SuffixCountableRange": run_SuffixCountableRange,
283285
"SuffixSequence": run_SuffixSequence,
284286
"SuperChars": run_SuperChars,

0 commit comments

Comments
 (0)