@@ -15,44 +15,58 @@ import TestsUtils
15
15
public let FlattenDistanceFromTo = [
16
16
BenchmarkInfo (
17
17
name: " FlattenDistanceFromTo.RandomAccess.16x16 " ,
18
- runFunction: { withRandomAccess ( 16 , 16 , $0) } ,
19
- tags: [ . validation, . api] ) ,
20
-
18
+ runFunction: { with ( randomAccess16x16, $0) } ,
19
+ tags: [ . validation, . api] ,
20
+ setUpFunction: { blackHole ( randomAccess16x16) } ) ,
21
+
21
22
BenchmarkInfo (
22
23
name: " FlattenDistanceFromTo.RandomAccess.16x32 " ,
23
- runFunction: { withRandomAccess ( 16 , 32 , $0) } ,
24
- tags: [ . validation, . api] ) ,
25
-
24
+ runFunction: { with ( randomAccess16x32, $0) } ,
25
+ tags: [ . validation, . api] ,
26
+ setUpFunction: { blackHole ( randomAccess16x32) } ) ,
27
+
26
28
BenchmarkInfo (
27
29
name: " FlattenDistanceFromTo.RandomAccess.32x16 " ,
28
- runFunction: { withRandomAccess ( 32 , 16 , $0) } ,
29
- tags: [ . validation, . api] ) ,
30
-
30
+ runFunction: { with ( randomAccess32x16, $0) } ,
31
+ tags: [ . validation, . api] ,
32
+ setUpFunction: { blackHole ( randomAccess32x16) } ) ,
33
+
31
34
BenchmarkInfo (
32
35
name: " FlattenDistanceFromTo.RandomAccess.32x32 " ,
33
- runFunction: { withRandomAccess ( 32 , 32 , $0) } ,
34
- tags: [ . validation, . api] ) ,
36
+ runFunction: { with ( randomAccess32x32, $0) } ,
37
+ tags: [ . validation, . api] ,
38
+ setUpFunction: { blackHole ( randomAccess32x32) } ) ,
35
39
]
36
40
37
- @inline ( never)
38
- public func withRandomAccess(
41
+ // MARK: - Random Access
42
+
43
+ func makeRandomAccess(
39
44
_ outer: Int ,
40
- _ inner: Int ,
45
+ _ inner: Int
46
+ ) -> FlattenSequence < Repeated < Repeated < Int > > > {
47
+ repeatElement ( repeatElement ( 0 , count: inner) , count: outer) . joined ( )
48
+ }
49
+
50
+ let randomAccess16x16 = makeRandomAccess ( 16 , 16 )
51
+ let randomAccess16x32 = makeRandomAccess ( 16 , 32 )
52
+ let randomAccess32x16 = makeRandomAccess ( 32 , 16 )
53
+ let randomAccess32x32 = makeRandomAccess ( 32 , 32 )
54
+
55
+ @inline ( never)
56
+ public func with(
57
+ _ collection: FlattenSequence < Repeated < Repeated < Int > > > ,
41
58
_ iterations: Int
42
59
) {
43
60
var value = 0 as Int
44
- let minor = repeatElement ( 00000 , count: inner)
45
- let major = repeatElement ( minor, count: outer)
46
- let flattened : FlattenSequence = major. joined ( )
47
-
61
+
48
62
for _ in 0 ..< iterations {
49
- for a in flattened . indices {
50
- for b in flattened . indices {
51
- value &+= flattened . distance ( from: a, to: b)
52
- value &+= flattened . distance ( from: b, to: a)
63
+ for a in collection . indices {
64
+ for b in collection . indices {
65
+ value &+= collection . distance ( from: a, to: b)
66
+ value &+= collection . distance ( from: b, to: a)
53
67
}
54
68
}
55
69
}
56
-
70
+
57
71
blackHole ( value == 0 )
58
72
}
0 commit comments