@@ -36,6 +36,30 @@ public let FlattenDistanceFromTo = [
36
36
runFunction: { with ( randomAccess32x32, $0) } ,
37
37
tags: [ . validation, . api] ,
38
38
setUpFunction: { blackHole ( randomAccess32x32) } ) ,
39
+
40
+ BenchmarkInfo (
41
+ name: " FlattenDistanceFromTo.RepeatString.08x08 " ,
42
+ runFunction: { with ( repeatString08x08, $0) } ,
43
+ tags: [ . validation, . api] ,
44
+ setUpFunction: { blackHole ( repeatString08x08) } ) ,
45
+
46
+ BenchmarkInfo (
47
+ name: " FlattenDistanceFromTo.RepeatString.08x16 " ,
48
+ runFunction: { with ( repeatString08x16, $0) } ,
49
+ tags: [ . validation, . api] ,
50
+ setUpFunction: { blackHole ( repeatString08x16) } ) ,
51
+
52
+ BenchmarkInfo (
53
+ name: " FlattenDistanceFromTo.RepeatString.16x08 " ,
54
+ runFunction: { with ( repeatString16x08, $0) } ,
55
+ tags: [ . validation, . api] ,
56
+ setUpFunction: { blackHole ( repeatString16x08) } ) ,
57
+
58
+ BenchmarkInfo (
59
+ name: " FlattenDistanceFromTo.RepeatString.16x16 " ,
60
+ runFunction: { with ( repeatString16x16, $0) } ,
61
+ tags: [ . validation, . api] ,
62
+ setUpFunction: { blackHole ( repeatString16x16) } ) ,
39
63
]
40
64
41
65
// MARK: - Random Access
@@ -58,7 +82,40 @@ public func with(
58
82
_ iterations: Int
59
83
) {
60
84
var value = 0 as Int
85
+
86
+ for _ in 0 ..< iterations {
87
+ for a in collection. indices {
88
+ for b in collection. indices {
89
+ value &+= collection. distance ( from: a, to: b)
90
+ value &+= collection. distance ( from: b, to: a)
91
+ }
92
+ }
93
+ }
94
+
95
+ blackHole ( value == 0 )
96
+ }
97
+
98
+ // MARK: - Repeat String
99
+
100
+ func makeRepeatString(
101
+ _ outer: Int ,
102
+ _ inner: Int
103
+ ) -> FlattenSequence < Repeated < String > > {
104
+ repeatElement ( String ( repeating: " 0 " , count: inner) , count: outer) . joined ( )
105
+ }
61
106
107
+ let repeatString08x08 = makeRepeatString ( 08 , 08 )
108
+ let repeatString08x16 = makeRepeatString ( 08 , 16 )
109
+ let repeatString16x08 = makeRepeatString ( 16 , 08 )
110
+ let repeatString16x16 = makeRepeatString ( 16 , 16 )
111
+
112
+ @inline ( never)
113
+ public func with(
114
+ _ collection: FlattenSequence < Repeated < String > > ,
115
+ _ iterations: Int
116
+ ) {
117
+ var value = 0 as Int
118
+
62
119
for _ in 0 ..< iterations {
63
120
for a in collection. indices {
64
121
for b in collection. indices {
0 commit comments