@@ -279,18 +279,27 @@ public let DataBenchmarks = [
279
279
legacyFactor: 50 ) ,
280
280
281
281
BenchmarkInfo ( name: " StringToDataEmpty " ,
282
- runFunction: { data ( $0* 200 , from: emptyString) } , tags: d,
282
+ runFunction: { dataFromUTF8View ( $0* 200 , from: emptyString) } , tags: d,
283
283
legacyFactor: 50 ) ,
284
284
BenchmarkInfo ( name: " StringToDataSmall " ,
285
- runFunction: { data ( $0* 200 , from: smallString) } , tags: d,
285
+ runFunction: { dataFromUTF8View ( $0* 200 , from: smallString) } , tags: d,
286
286
legacyFactor: 50 ) ,
287
287
BenchmarkInfo ( name: " StringToDataMedium " ,
288
- runFunction: { data ( $0* 200 , from: mediumString) } , tags: d,
288
+ runFunction: { dataFromUTF8View ( $0* 200 , from: mediumString) } , tags: d,
289
289
legacyFactor: 50 ) ,
290
290
BenchmarkInfo ( name: " StringToDataLargeUnicode " ,
291
- runFunction: { data ( $0* 200 , from: largeUnicodeString) } , tags: d,
291
+ runFunction: { dataFromUTF8View ( $0* 200 , from: largeUnicodeString) } , tags: d,
292
292
legacyFactor: 50 ) ,
293
293
294
+ BenchmarkInfo ( name: " String.data.Empty " ,
295
+ runFunction: { dataUsingUTF8Encoding ( $0* 200 , from: emptyString) } , tags: d) ,
296
+ BenchmarkInfo ( name: " String.data.Small " ,
297
+ runFunction: { dataUsingUTF8Encoding ( $0* 200 , from: smallString) } , tags: d) ,
298
+ BenchmarkInfo ( name: " String.data.Medium " ,
299
+ runFunction: { dataUsingUTF8Encoding ( $0* 200 , from: mediumString) } , tags: d) ,
300
+ BenchmarkInfo ( name: " String.data.LargeUnicode " ,
301
+ runFunction: { dataUsingUTF8Encoding ( $0* 200 , from: largeUnicodeString) } , tags: d) ,
302
+
294
303
BenchmarkInfo ( name: " Data.hash.Empty " ,
295
304
runFunction: { hash ( $0* 10_000 , data: Data ( ) ) } , tags: d) ,
296
305
BenchmarkInfo ( name: " Data.hash.Small " ,
@@ -530,12 +539,19 @@ public func string(_ N: Int, from data: Data) {
530
539
}
531
540
532
541
@inline ( never)
533
- public func data ( _ N: Int , from string: String ) {
542
+ public func dataFromUTF8View ( _ N: Int , from string: String ) {
534
543
for _ in 1 ... N {
535
544
blackHole ( Data ( string. utf8) )
536
545
}
537
546
}
538
547
548
+ @inline ( never)
549
+ public func dataUsingUTF8Encoding( _ N: Int , from string: String ) {
550
+ for _ in 1 ... N {
551
+ autoreleasepool { blackHole ( string. data ( using: . utf8) ) }
552
+ }
553
+ }
554
+
539
555
@inline ( never)
540
556
public func hash( _ N: Int , data: Data ) {
541
557
var hasher = Hasher ( )
0 commit comments