@@ -40,12 +40,89 @@ public let DataBenchmarks = [
40
40
0 , 1 , 2 , 3 , 4 , 5 , 6 ,
41
41
] ) ) } } , tags: d, legacyFactor: 20 ) ,
42
42
43
- BenchmarkInfo ( name: " Data.init.Sequence.ExactCount " , runFunction: {
43
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count " , runFunction: {
44
+ _init ( $0* 100 , sequence: Bytes ( count: 809 , exact: true ) ) } , tags: d) ,
45
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count0 " , runFunction: {
46
+ _init ( $0* 100 , sequence: Bytes ( count: 809 , exact: false ) ) } , tags: d) ,
47
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count.I " , runFunction: {
48
+ for _ in 0 ..< $0* 100 {
49
+ blackHole ( Data ( Bytes ( count: 809 , exact: true ) ) ) } } , tags: d) ,
50
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count0.I " , runFunction: {
51
+ for _ in 0 ..< $0* 100 {
52
+ blackHole ( Data ( Bytes ( count: 809 , exact: false ) ) ) } } , tags: d) ,
53
+ BenchmarkInfo ( name: " Data.init.Sequence.2047B.Count.I " , runFunction: {
54
+ for _ in 0 ..< $0* 50 {
55
+ blackHole ( Data ( Bytes ( count: 2047 , exact: true ) ) ) } } , tags: d) ,
56
+ BenchmarkInfo ( name: " Data.init.Sequence.2047B.Count0.I " , runFunction: {
57
+ for _ in 0 ..< $0* 50 {
58
+ blackHole ( Data ( Bytes ( count: 2047 , exact: false ) ) ) } } , tags: d) ,
59
+ BenchmarkInfo ( name: " Data.init.Sequence.2049B.Count.I " , runFunction: {
60
+ for _ in 0 ..< $0* 50 {
61
+ blackHole ( Data ( Bytes ( count: 2049 , exact: true ) ) ) } } , tags: d) ,
62
+ BenchmarkInfo ( name: " Data.init.Sequence.2049B.Count0.I " , runFunction: {
63
+ for _ in 0 ..< $0* 50 {
64
+ blackHole ( Data ( Bytes ( count: 2049 , exact: false ) ) ) } } , tags: d) ,
65
+ BenchmarkInfo ( name: " Data.init.Sequence.511B.Count.I " , runFunction: {
66
+ for _ in 0 ..< $0* 150 {
67
+ blackHole ( Data ( Bytes ( count: 511 , exact: true ) ) ) } } , tags: d) ,
68
+ BenchmarkInfo ( name: " Data.init.Sequence.511B.Count0.I " , runFunction: {
69
+ for _ in 0 ..< $0* 150 {
70
+ blackHole ( Data ( Bytes ( count: 511 , exact: false ) ) ) } } , tags: d) ,
71
+ BenchmarkInfo ( name: " Data.init.Sequence.513B.Count.I " , runFunction: {
72
+ for _ in 0 ..< $0* 150 {
73
+ blackHole ( Data ( Bytes ( count: 513 , exact: true ) ) ) } } , tags: d) ,
74
+ BenchmarkInfo ( name: " Data.init.Sequence.513B.Count0.I " , runFunction: {
75
+ for _ in 0 ..< $0* 150 {
76
+ blackHole ( Data ( Bytes ( count: 513 , exact: false ) ) ) } } , tags: d) ,
77
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count " , runFunction: {
78
+ _init ( $0, sequence: Bytes ( count: 2 <<15 , exact: true ) ) } , tags: d) ,
79
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count0 " , runFunction: {
80
+ _init ( $0, sequence: Bytes ( count: 2 <<15 , exact: false ) ) } , tags: d) ,
81
+ BenchmarkInfo ( name: " Array.init.Sequence.64kB.Count.I " , runFunction: {
82
+ for _ in 1 ... $0 {
83
+ blackHole ( Array ( Bytes ( count: 2 <<15 , exact: true ) ) ) } } , tags: d) ,
84
+ BenchmarkInfo ( name: " Array.init.Sequence.64kB.Count0.I " , runFunction: {
85
+ for _ in 1 ... $0 {
86
+ blackHole ( Array ( Bytes ( count: 2 <<15 , exact: false ) ) ) } } , tags: d) ,
87
+ BenchmarkInfo ( name: " Array.init.Sequence.64kB.Count.RE.I " , runFunction: {
88
+ for _ in 1 ... $0 {
89
+ blackHole ( Array ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ) } } , tags: d) ,
90
+ BenchmarkInfo ( name: " Array.init.Sequence.64kB.Count0.RE.I " , runFunction: {
91
+ for _ in 1 ... $0 {
92
+ blackHole ( Array ( Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ) ) } } ,
93
+ tags: d) ,
94
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count.I " , runFunction: {
95
+ for _ in 0 ..< $0 {
96
+ blackHole ( Data ( Bytes ( count: 2 <<15 , exact: true ) ) ) } } , tags: d) ,
97
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count0.I " , runFunction: {
98
+ for _ in 0 ..< $0 {
99
+ blackHole ( Data ( Bytes ( count: 2 <<15 , exact: false ) ) ) } } , tags: d) ,
100
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count.RE " , runFunction: {
101
+ _init ( $0* 100 , sequence: repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) } , tags: d) ,
102
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count0.RE " , runFunction: {
103
+ _init ( $0* 100 , sequence: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) ) } ,
104
+ tags: d) ,
105
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count.RE.I " , runFunction: {
44
106
for _ in 0 ..< $0* 100 {
45
107
blackHole ( Data ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) )
46
108
} } , tags: d) ,
47
- BenchmarkInfo ( name: " Data.init.Sequence.UnderestimatedCount " , runFunction: {
48
- for _ in 0 ..< $0* 100 { blackHole ( Data ( repeatElementSeq ( 809 ) ) ) } } , tags: d) ,
109
+ BenchmarkInfo ( name: " Data.init.Sequence.809B.Count0.RE.I " , runFunction: {
110
+ for _ in 0 ..< $0* 100 {
111
+ blackHole ( Data ( Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) ) )
112
+ } } , tags: d) ,
113
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count.RE " , runFunction: {
114
+ _init ( $0, sequence: repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) } , tags: d) ,
115
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count0.RE " , runFunction: {
116
+ _init ( $0, sequence: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ) } ,
117
+ tags: d) ,
118
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count.RE.I " , runFunction: {
119
+ for _ in 0 ..< $0 {
120
+ blackHole ( Data ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) )
121
+ } } , tags: d) ,
122
+ BenchmarkInfo ( name: " Data.init.Sequence.64kB.Count0.RE.I " , runFunction: {
123
+ for _ in 0 ..< $0 {
124
+ blackHole ( Data ( Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ) )
125
+ } } , tags: d) ,
49
126
50
127
BenchmarkInfo ( name: " DataSubscriptSmall " ,
51
128
runFunction: { let data = small
@@ -120,12 +197,72 @@ public let DataBenchmarks = [
120
197
BenchmarkInfo ( name: " DataAppendSequence " ,
121
198
runFunction: { append ( $0* 100 , sequenceLength: 809 , to: medium) } ,
122
199
tags: d, legacyFactor: 100 ) ,
123
- BenchmarkInfo ( name: " Data.append.Sequence.ExactCount " , runFunction: {
200
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count " , runFunction: {
201
+ append ( $0* 100 , sequence: Bytes ( count: 809 , exact: true ) , to: medium) } ,
202
+ tags: d) ,
203
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count0 " , runFunction: {
204
+ append ( $0* 100 , sequence: Bytes ( count: 809 , exact: false ) , to: medium) } ,
205
+ tags: d) ,
206
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count.I " ,
207
+ runFunction: { for _ in 1 ... $0* 100 { var copy = medium
208
+ copy. append ( contentsOf: Bytes ( count: 809 , exact: true ) ) } } , tags: d) ,
209
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count0.I " ,
210
+ runFunction: { for _ in 1 ... $0* 100 { var copy = medium
211
+ copy. append ( contentsOf: Bytes ( count: 809 , exact: false ) ) } } , tags: d) ,
212
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count " , runFunction: {
213
+ append ( $0, sequence: Bytes ( count: 2 <<15 , exact: true ) , to: medium) } ,
214
+ tags: d) ,
215
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count0 " , runFunction: {
216
+ append ( $0, sequence: Bytes ( count: 2 <<15 , exact: false ) , to: medium) } ,
217
+ tags: d) ,
218
+ BenchmarkInfo ( name: " Array.append.Sequence.64kB.Count.I " , runFunction: {
219
+ for _ in 1 ... $0 { var copy = mediumArray
220
+ copy. append ( contentsOf: Bytes ( count: 2 <<15 , exact: true ) ) } } , tags: d) ,
221
+ BenchmarkInfo ( name: " Array.append.Sequence.64kB.Count0.I " , runFunction: {
222
+ for _ in 1 ... $0 { var copy = mediumArray
223
+ copy. append ( contentsOf: Bytes ( count: 2 <<15 , exact: false ) ) } } , tags: d) ,
224
+ BenchmarkInfo ( name: " Array.append.Sequence.64kB.Count.RE.I " , runFunction: {
225
+ for _ in 1 ... $0 { var copy = mediumArray
226
+ copy. append ( contentsOf: repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) } } ,
227
+ tags: d) ,
228
+ BenchmarkInfo ( name: " Array.append.Sequence.64kB.Count0.RE.I " , runFunction: {
229
+ for _ in 1 ... $0 { var copy = mediumArray
230
+ copy. append ( contentsOf: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) )
231
+ } } , tags: d) ,
232
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count.I " , runFunction: {
233
+ for _ in 1 ... $0 { var copy = medium
234
+ copy. append ( contentsOf: Bytes ( count: 2 <<15 , exact: true ) ) } } , tags: d) ,
235
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count0.I " , runFunction: {
236
+ for _ in 1 ... $0 { var copy = medium
237
+ copy. append ( contentsOf: Bytes ( count: 2 <<15 , exact: false ) ) } } , tags: d) ,
238
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count.RE.I " , runFunction: {
239
+ for _ in 1 ... $0* 100 { var copy = medium
240
+ copy. append ( contentsOf: repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) } } ,
241
+ tags: d) ,
242
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count0.RE.I " , runFunction: {
243
+ for _ in 1 ... $0* 100 { var copy = medium
244
+ copy. append ( contentsOf: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) ) } } ,
245
+ tags: d) ,
246
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count.RE " , runFunction: {
124
247
append ( $0* 100 , sequence: repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ,
125
248
to: medium) } , tags: d) ,
126
- BenchmarkInfo ( name: " Data.append.Sequence.UnderestimatedCount " , runFunction: {
127
- append ( $0* 100 , sequence: repeatElementSeq ( 809 ) , to: medium) } ,
249
+ BenchmarkInfo ( name: " Data.append.Sequence.809B.Count0.RE " , runFunction: {
250
+ append ( $0* 100 , sequence: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 809 ) ) ,
251
+ to: medium) } , tags: d) ,
252
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count.RE.I " , runFunction: {
253
+ for _ in 1 ... $0 { var copy = medium
254
+ copy. append ( contentsOf: repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) } } ,
128
255
tags: d) ,
256
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count0.RE.I " , runFunction: {
257
+ for _ in 1 ... $0 { var copy = medium
258
+ copy. append ( contentsOf: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ) }
259
+ } , tags: d) ,
260
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count.RE " , runFunction: {
261
+ append ( $0, sequence: repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ,
262
+ to: medium) } , tags: d) ,
263
+ BenchmarkInfo ( name: " Data.append.Sequence.64kB.Count0.RE " , runFunction: {
264
+ append ( $0, sequence: Count0 ( repeatElement ( UInt8 ( 0xA0 ) , count: 2 <<15 ) ) ,
265
+ to: medium) } , tags: d) ,
129
266
130
267
BenchmarkInfo ( name: " DataAppendDataSmallToSmall " ,
131
268
runFunction: { append ( $0* 500 , data: small, to: small) } , tags: d,
@@ -194,12 +331,38 @@ let small = sampleData(.small)
194
331
let medium = sampleData ( . medium)
195
332
let large = sampleData ( . large)
196
333
334
+ let mediumArray : [ UInt8 ] = ( 1 ... 1033 ) . map { UInt8 ( truncatingIfNeeded: $0) }
335
+
197
336
let repeatElementSeq = { count in
198
337
return sequence ( state: count) { ( i: inout Int ) -> UInt8 ? in
199
338
defer { i = i &- 1 } ; return i > 0 ? UInt8 ( 0xA0 ) : nil
200
339
}
201
340
}
202
341
342
+ struct Count0 < S: Sequence > : Sequence {
343
+ let base : S
344
+ init ( _ base: S ) { self . base = base }
345
+ func makeIterator( ) -> S . Iterator { return base. makeIterator ( ) }
346
+ var underestimatedCount : Int { return 0 }
347
+ }
348
+
349
+ struct Bytes : Sequence , IteratorProtocol {
350
+ let count : Int
351
+ let exact : Bool
352
+ var i : Int = 0
353
+ init ( count: Int , exact: Bool ) {
354
+ self . count = count
355
+ self . exact = exact
356
+ }
357
+ mutating func next( ) -> UInt8 ? {
358
+ defer { i = i &+ 1 }
359
+ return ( i < count) ? UInt8 ( truncatingIfNeeded: i) : nil
360
+ }
361
+ var underestimatedCount : Int {
362
+ return exact ? count : 0
363
+ }
364
+ }
365
+
203
366
enum SampleKind {
204
367
case small
205
368
case medium
@@ -315,6 +478,13 @@ where S.Element == UInt8 {
315
478
}
316
479
}
317
480
481
+ @inline ( never)
482
+ func _init< S: Sequence > ( _ N: Int , sequence: S ) where S. Element == UInt8 {
483
+ for _ in 1 ... N {
484
+ blackHole ( Data ( sequence) )
485
+ }
486
+ }
487
+
318
488
@inline ( never)
319
489
func resetBytes( _ N: Int , in range: Range < Data . Index > , data: Data ) {
320
490
for _ in 1 ... N {
0 commit comments