@@ -14,7 +14,6 @@ import TestsUtils
14
14
import Foundation
15
15
16
16
let d : [ BenchmarkCategory ] = [ . validation, . api, . Data]
17
- let skip : [ BenchmarkCategory ] = [ . validation, . api, . Data, . skip]
18
17
19
18
public let DataBenchmarks = [
20
19
BenchmarkInfo ( name: " DataCreateEmpty " ,
@@ -87,12 +86,15 @@ public let DataBenchmarks = [
87
86
BenchmarkInfo ( name: " DataReplaceLarge " , runFunction: {
88
87
replace ( $0, data: medium, subrange: 431 ..< 809 , with: large) } , tags: d) ,
89
88
90
- BenchmarkInfo ( name: " DataReplaceSmallBuffer " ,
91
- runFunction: run_ReplaceSmallBuffer, tags: d) ,
92
- BenchmarkInfo ( name: " DataReplaceMediumBuffer " ,
93
- runFunction: run_ReplaceMediumBuffer, tags: d) ,
94
- BenchmarkInfo ( name: " DataReplaceLargeBuffer " ,
95
- runFunction: run_ReplaceLargeBuffer, tags: skip) ,
89
+ BenchmarkInfo ( name: " DataReplaceSmallBuffer " , runFunction: {
90
+ replaceBuffer ( $0, data: medium, subrange: 431 ..< 809 , with: small) } ,
91
+ tags: d) ,
92
+ BenchmarkInfo ( name: " DataReplaceMediumBuffer " , runFunction: {
93
+ replaceBuffer ( $0, data: medium, subrange: 431 ..< 809 , with: medium) } ,
94
+ tags: d) ,
95
+ BenchmarkInfo ( name: " DataReplaceLargeBuffer " , runFunction: {
96
+ replaceBuffer ( $0, data: medium, subrange: 431 ..< 809 , with: large) } ,
97
+ tags: d) ,
96
98
97
99
BenchmarkInfo ( name: " DataAppendSequence " ,
98
100
runFunction: { append ( $0, sequenceLength: 809 , to: medium) } , tags: d) ,
@@ -262,10 +264,20 @@ func replace(
262
264
}
263
265
}
264
266
265
- func benchmark_ReplaceBuffer( _ N: Int , _ range: Range < Data . Index > , _ data_: Data , _ replacement: UnsafeBufferPointer < UInt8 > ) {
266
- for _ in 0 ..< 10000 * N {
267
- var data = data_
268
- data. replaceSubrange ( range, with: replacement)
267
+ @inline ( never)
268
+ func replaceBuffer(
269
+ _ N: Int ,
270
+ data: Data ,
271
+ subrange range: Range < Data . Index > ,
272
+ with replacement: Data
273
+ ) {
274
+ replacement. withUnsafeBytes { ( bytes: UnsafePointer < UInt8 > ) in
275
+ let buffer = UnsafeBufferPointer ( start: bytes, count: replacement. count)
276
+
277
+ for _ in 0 ..< 10000 * N {
278
+ var copy = data
279
+ copy. replaceSubrange ( range, with: buffer)
280
+ }
269
281
}
270
282
}
271
283
@@ -296,36 +308,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) {
296
308
}
297
309
}
298
310
299
- @inline ( never)
300
- public func run_ReplaceSmallBuffer( _ N: Int ) {
301
- let data = sampleData ( . medium)
302
- let replacement = sampleData ( . small)
303
- let sz = replacement. count
304
- replacement. withUnsafeBytes { ( ptr: UnsafePointer < UInt8 > ) in
305
- benchmark_ReplaceBuffer ( N, 431 ..< 809 , data, UnsafeBufferPointer ( start: ptr, count: sz) )
306
- }
307
- }
308
-
309
- @inline ( never)
310
- public func run_ReplaceMediumBuffer( _ N: Int ) {
311
- let data = sampleData ( . medium)
312
- let replacement = sampleData ( . medium)
313
- let sz = replacement. count
314
- replacement. withUnsafeBytes { ( ptr: UnsafePointer < UInt8 > ) in
315
- benchmark_ReplaceBuffer ( N, 431 ..< 809 , data, UnsafeBufferPointer ( start: ptr, count: sz) )
316
- }
317
- }
318
-
319
- @inline ( never)
320
- public func run_ReplaceLargeBuffer( _ N: Int ) {
321
- let data = sampleData ( . medium)
322
- let replacement = sampleData ( . large)
323
- let sz = replacement. count
324
- replacement. withUnsafeBytes { ( ptr: UnsafePointer < UInt8 > ) in
325
- benchmark_ReplaceBuffer ( N, 431 ..< 809 , data, UnsafeBufferPointer ( start: ptr, count: sz) )
326
- }
327
- }
328
-
329
311
@inline ( never)
330
312
public func run_DataToStringEmpty( _ N: Int ) {
331
313
let d = Data ( )
0 commit comments