@@ -40,6 +40,13 @@ public let DataBenchmarks = [
40
40
0 , 1 , 2 , 3 , 4 , 5 , 6 ,
41
41
] ) ) } } , tags: d, legacyFactor: 20 ) ,
42
42
43
+ BenchmarkInfo ( name: " DataCreateSequenceExactCount " , runFunction: {
44
+ for _ in 0 ..< $0* 500 {
45
+ blackHole ( Data ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) )
46
+ } } , tags: d) ,
47
+ BenchmarkInfo ( name: " DataCreateSequenceUnderestimatedCount " , runFunction: {
48
+ for _ in 0 ..< $0* 500 { blackHole ( Data ( repeatElementSeq ( 809 ) ) ) } } , tags: d) ,
49
+
43
50
BenchmarkInfo ( name: " DataSubscriptSmall " ,
44
51
runFunction: { let data = small
45
52
for _ in 0 ..< $0* 10_000 { blackHole ( data [ 1 ] ) } } , tags: d) ,
@@ -110,9 +117,12 @@ public let DataBenchmarks = [
110
117
replaceBuffer ( $0* 10 , data: medium, subrange: 431 ..< 809 , with: large) } ,
111
118
tags: d) ,
112
119
113
- BenchmarkInfo ( name: " DataAppendSequence " ,
120
+ BenchmarkInfo ( name: " DataAppendSequenceExactCount " ,
114
121
runFunction: { append ( $0* 100 , sequenceLength: 809 , to: medium) } ,
115
- tags: d, legacyFactor: 100 ) ,
122
+ tags: d, legacyFactor: 100 ) ,
123
+ BenchmarkInfo ( name: " DataAppendSequenceUnderestimatedCount " , runFunction: {
124
+ append ( $0* 100 , sequence: repeatElementSeq ( 809 ) , to: medium) } ,
125
+ tags: d, legacyFactor: 100 ) ,
116
126
117
127
BenchmarkInfo ( name: " DataAppendDataSmallToSmall " ,
118
128
runFunction: { append ( $0* 500 , data: small, to: small) } , tags: d,
@@ -174,6 +184,12 @@ let small = sampleData(.small)
174
184
let medium = sampleData ( . medium)
175
185
let large = sampleData ( . large)
176
186
187
+ let repeatElementSeq = { count in
188
+ return sequence ( state: count) { ( i: inout Int ) -> UInt8 ? in
189
+ defer { i = i &- 1 } ; return i > 0 ? UInt8 ( 0xA0 ) : nil
190
+ }
191
+ }
192
+
177
193
enum SampleKind {
178
194
case small
179
195
case medium
@@ -280,6 +296,15 @@ func append(_ N: Int, sequenceLength: Int, to data: Data) {
280
296
}
281
297
}
282
298
299
+ @inline ( never)
300
+ func append< S: Sequence > ( _ N: Int , sequence: S , to data: Data )
301
+ where S. Element == UInt8 {
302
+ for _ in 1 ... N {
303
+ var copy = data
304
+ copy. append ( contentsOf: sequence)
305
+ }
306
+ }
307
+
283
308
@inline ( never)
284
309
func resetBytes( _ N: Int , in range: Range < Data . Index > , data: Data ) {
285
310
for _ in 1 ... N {
0 commit comments