Skip to content

Commit 739c3b7

Browse files
committed
Add same test variants for DropLast and Prefix as exist on Suffix
1 parent 7c103d8 commit 739c3b7

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

benchmark/single-source/DropLast.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ let prefixCount = 1024
2323
let dropCount = sequenceCount - prefixCount
2424
let sumCount = prefixCount * (prefixCount - 1) / 2
2525

26-
2726
@inline(never)
2827
public func run_DropLastCountableRange(_ N: Int) {
2928
let s = 0..<sequenceCount
@@ -73,6 +72,18 @@ public func run_DropLastAnySeqCntRange(_ N: Int) {
7372
}
7473
}
7574
@inline(never)
75+
public func run_DropLastAnySeqCRangeIter(_ N: Int) {
76+
let s = AnySequence((0..<sequenceCount).makeIterator())
77+
for _ in 1...20*N {
78+
var result = 0
79+
for element in s.dropLast(dropCount) {
80+
result += element
81+
}
82+
CheckResults(result == sumCount,
83+
"IncorrectResults in DropLastAnySeqCRangeIter: \(result) != \(sumCount)")
84+
}
85+
}
86+
@inline(never)
7687
public func run_DropLastAnyCollection(_ N: Int) {
7788
let s = AnyCollection(0..<sequenceCount)
7889
for _ in 1...20*N {
@@ -145,6 +156,18 @@ public func run_DropLastAnySeqCntRangeLazy(_ N: Int) {
145156
}
146157
}
147158
@inline(never)
159+
public func run_DropLastAnySeqCRangeIterLazy(_ N: Int) {
160+
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
161+
for _ in 1...20*N {
162+
var result = 0
163+
for element in s.dropLast(dropCount) {
164+
result += element
165+
}
166+
CheckResults(result == sumCount,
167+
"IncorrectResults in DropLastAnySeqCRangeIterLazy: \(result) != \(sumCount)")
168+
}
169+
}
170+
@inline(never)
148171
public func run_DropLastAnyCollectionLazy(_ N: Int) {
149172
let s = (AnyCollection(0..<sequenceCount)).lazy
150173
for _ in 1...20*N {

benchmark/single-source/DropLast.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ let sequenceCount = 4096
2323
let prefixCount = 1024
2424
let dropCount = sequenceCount - prefixCount
2525
let sumCount = prefixCount * (prefixCount - 1) / 2
26-
2726
%{
2827
# Name and Expression pairs for Sequences to test.
2928

@@ -34,6 +33,7 @@ Sequences = [
3433
('AnySequence',
3534
'AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })'),
3635
('AnySeqCntRange', 'AnySequence(0..<sequenceCount)'),
36+
('AnySeqCRangeIter', 'AnySequence((0..<sequenceCount).makeIterator())'),
3737
('AnyCollection', 'AnyCollection(0..<sequenceCount)'),
3838
('Array', 'Array(0..<sequenceCount)'),
3939
]

benchmark/single-source/Prefix.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let sequenceCount = 4096
2222
let prefixCount = sequenceCount - 1024
2323
let sumCount = prefixCount * (prefixCount - 1) / 2
2424

25-
2625
@inline(never)
2726
public func run_PrefixCountableRange(_ N: Int) {
2827
let s = 0..<sequenceCount
@@ -72,6 +71,18 @@ public func run_PrefixAnySeqCntRange(_ N: Int) {
7271
}
7372
}
7473
@inline(never)
74+
public func run_PrefixAnySeqCRangeIter(_ N: Int) {
75+
let s = AnySequence((0..<sequenceCount).makeIterator())
76+
for _ in 1...20*N {
77+
var result = 0
78+
for element in s.prefix(prefixCount) {
79+
result += element
80+
}
81+
CheckResults(result == sumCount,
82+
"IncorrectResults in PrefixAnySeqCRangeIter: \(result) != \(sumCount)")
83+
}
84+
}
85+
@inline(never)
7586
public func run_PrefixAnyCollection(_ N: Int) {
7687
let s = AnyCollection(0..<sequenceCount)
7788
for _ in 1...20*N {
@@ -144,6 +155,18 @@ public func run_PrefixAnySeqCntRangeLazy(_ N: Int) {
144155
}
145156
}
146157
@inline(never)
158+
public func run_PrefixAnySeqCRangeIterLazy(_ N: Int) {
159+
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
160+
for _ in 1...20*N {
161+
var result = 0
162+
for element in s.prefix(prefixCount) {
163+
result += element
164+
}
165+
CheckResults(result == sumCount,
166+
"IncorrectResults in PrefixAnySeqCRangeIterLazy: \(result) != \(sumCount)")
167+
}
168+
}
169+
@inline(never)
147170
public func run_PrefixAnyCollectionLazy(_ N: Int) {
148171
let s = (AnyCollection(0..<sequenceCount)).lazy
149172
for _ in 1...20*N {

benchmark/single-source/Prefix.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import TestsUtils
2222
let sequenceCount = 4096
2323
let prefixCount = sequenceCount - 1024
2424
let sumCount = prefixCount * (prefixCount - 1) / 2
25-
2625
%{
2726
# Name and initializer Expression pairs for Sequences to test.
2827

@@ -33,6 +32,7 @@ Sequences = [
3332
('AnySequence',
3433
'AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })'),
3534
('AnySeqCntRange', 'AnySequence(0..<sequenceCount)'),
35+
('AnySeqCRangeIter', 'AnySequence((0..<sequenceCount).makeIterator())'),
3636
('AnyCollection', 'AnyCollection(0..<sequenceCount)'),
3737
('Array', 'Array(0..<sequenceCount)'),
3838
]

benchmark/utils/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ precommitTests = [
175175
"DictionarySwapOfObjects": run_DictionarySwapOfObjects,
176176
"DropLastAnyCollection": run_DropLastAnyCollection,
177177
"DropLastAnyCollectionLazy": run_DropLastAnyCollectionLazy,
178+
"DropLastAnySeqCRangeIter": run_DropLastAnySeqCRangeIter,
179+
"DropLastAnySeqCRangeIterLazy": run_DropLastAnySeqCRangeIterLazy,
178180
"DropLastAnySeqCntRange": run_DropLastAnySeqCntRange,
179181
"DropLastAnySeqCntRangeLazy": run_DropLastAnySeqCntRangeLazy,
180182
"DropLastAnySequence": run_DropLastAnySequence,
@@ -364,6 +366,8 @@ precommitTests = [
364366
"PopFrontUnsafePointer": run_PopFrontUnsafePointer,
365367
"PrefixAnyCollection": run_PrefixAnyCollection,
366368
"PrefixAnyCollectionLazy": run_PrefixAnyCollectionLazy,
369+
"PrefixAnySeqCRangeIter": run_PrefixAnySeqCRangeIter,
370+
"PrefixAnySeqCRangeIterLazy": run_PrefixAnySeqCRangeIterLazy,
367371
"PrefixAnySeqCntRange": run_PrefixAnySeqCntRange,
368372
"PrefixAnySeqCntRangeLazy": run_PrefixAnySeqCntRangeLazy,
369373
"PrefixAnySequence": run_PrefixAnySequence,

0 commit comments

Comments
 (0)