Skip to content

Commit cef7c43

Browse files
committed
FlattenSequence/distance(from:to:) benchmarks (v5).
1. Replaced occurrences of Repeated<T> with Array<T>.
1 parent dff2747 commit cef7c43

File tree

1 file changed

+40
-52
lines changed

1 file changed

+40
-52
lines changed

benchmark/single-source/FlattenDistanceFromTo.swift

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,67 @@ import TestsUtils
1414

1515
public let FlattenDistanceFromTo = [
1616
BenchmarkInfo(
17-
name: "FlattenDistanceFromTo.RandomAccess.16x16",
18-
runFunction: { with(randomAccess16x16, $0) },
17+
name: "FlattenDistanceFromTo.Array.Array.16.16",
18+
runFunction: { with(arrayArray16x16, $0) },
1919
tags: [.validation, .api],
20-
setUpFunction: { blackHole(randomAccess16x16) }),
20+
setUpFunction: { blackHole(arrayArray16x16) }),
2121

2222
BenchmarkInfo(
23-
name: "FlattenDistanceFromTo.RandomAccess.16x32",
24-
runFunction: { with(randomAccess16x32, $0) },
23+
name: "FlattenDistanceFromTo.Array.Array.16.32",
24+
runFunction: { with(arrayArray16x32, $0) },
2525
tags: [.validation, .api],
26-
setUpFunction: { blackHole(randomAccess16x32) }),
26+
setUpFunction: { blackHole(arrayArray16x32) }),
2727

2828
BenchmarkInfo(
29-
name: "FlattenDistanceFromTo.RandomAccess.32x16",
30-
runFunction: { with(randomAccess32x16, $0) },
29+
name: "FlattenDistanceFromTo.Array.Array.32.16",
30+
runFunction: { with(arrayArray32x16, $0) },
3131
tags: [.validation, .api],
32-
setUpFunction: { blackHole(randomAccess32x16) }),
32+
setUpFunction: { blackHole(arrayArray32x16) }),
3333

3434
BenchmarkInfo(
35-
name: "FlattenDistanceFromTo.RandomAccess.32x32",
36-
runFunction: { with(randomAccess32x32, $0) },
35+
name: "FlattenDistanceFromTo.Array.Array.32.32",
36+
runFunction: { with(arrayArray32x32, $0) },
3737
tags: [.validation, .api],
38-
setUpFunction: { blackHole(randomAccess32x32) }),
38+
setUpFunction: { blackHole(arrayArray32x32) }),
3939

4040
BenchmarkInfo(
41-
name: "FlattenDistanceFromTo.RepeatString.08x08",
42-
runFunction: { with(repeatString08x08, $0) },
41+
name: "FlattenDistanceFromTo.Array.String.08.08",
42+
runFunction: { with(arrayString08x08, $0) },
4343
tags: [.validation, .api],
44-
setUpFunction: { blackHole(repeatString08x08) }),
44+
setUpFunction: { blackHole(arrayString08x08) }),
4545

4646
BenchmarkInfo(
47-
name: "FlattenDistanceFromTo.RepeatString.08x16",
48-
runFunction: { with(repeatString08x16, $0) },
47+
name: "FlattenDistanceFromTo.Array.String.08.16",
48+
runFunction: { with(arrayString08x16, $0) },
4949
tags: [.validation, .api],
50-
setUpFunction: { blackHole(repeatString08x16) }),
50+
setUpFunction: { blackHole(arrayString08x16) }),
5151

5252
BenchmarkInfo(
53-
name: "FlattenDistanceFromTo.RepeatString.16x08",
54-
runFunction: { with(repeatString16x08, $0) },
53+
name: "FlattenDistanceFromTo.Array.String.16.08",
54+
runFunction: { with(arrayString16x08, $0) },
5555
tags: [.validation, .api],
56-
setUpFunction: { blackHole(repeatString16x08) }),
56+
setUpFunction: { blackHole(arrayString16x08) }),
5757

5858
BenchmarkInfo(
59-
name: "FlattenDistanceFromTo.RepeatString.16x16",
60-
runFunction: { with(repeatString16x16, $0) },
59+
name: "FlattenDistanceFromTo.Array.String.16.16",
60+
runFunction: { with(arrayString16x16, $0) },
6161
tags: [.validation, .api],
62-
setUpFunction: { blackHole(repeatString16x16) }),
62+
setUpFunction: { blackHole(arrayString16x16) }),
6363
]
6464

65-
// MARK: - Random Access
65+
// MARK: - Array Array
6666

67-
func makeRandomAccess(
68-
_ outer: Int,
69-
_ inner: Int
70-
) -> FlattenSequence<Repeated<Repeated<Int>>> {
71-
repeatElement(repeatElement(0, count: inner), count: outer).joined()
67+
func makeArrayArray(_ outer: Int, _ inner: Int) -> FlattenSequence<[[UInt8]]> {
68+
Array(repeating: Array(repeating: 123, count: inner), count: outer).joined()
7269
}
7370

74-
let randomAccess16x16 = makeRandomAccess(16, 16)
75-
let randomAccess16x32 = makeRandomAccess(16, 32)
76-
let randomAccess32x16 = makeRandomAccess(32, 16)
77-
let randomAccess32x32 = makeRandomAccess(32, 32)
71+
let arrayArray16x16 = makeArrayArray(16, 16)
72+
let arrayArray16x32 = makeArrayArray(16, 32)
73+
let arrayArray32x16 = makeArrayArray(32, 16)
74+
let arrayArray32x32 = makeArrayArray(32, 32)
7875

7976
@inline(never)
80-
public func with(
81-
_ collection: FlattenSequence<Repeated<Repeated<Int>>>,
82-
_ iterations: Int
83-
) {
77+
public func with(_ collection: FlattenSequence<[[UInt8]]>, _ iterations: Int) {
8478
var value = 0 as Int
8579

8680
for _ in 0 ..< iterations {
@@ -95,25 +89,19 @@ public func with(
9589
blackHole(value == 0)
9690
}
9791

98-
// MARK: - Repeat String
92+
// MARK: - Array String
9993

100-
func makeRepeatString(
101-
_ outer: Int,
102-
_ inner: Int
103-
) -> FlattenSequence<Repeated<String>> {
104-
repeatElement(String(repeating: "0", count: inner), count: outer).joined()
94+
func makeArrayString(_ outer: Int, _ inner: Int) -> FlattenSequence<[String]> {
95+
Array(repeating: String(repeating: "0", count: inner), count: outer).joined()
10596
}
10697

107-
let repeatString08x08 = makeRepeatString(08, 08)
108-
let repeatString08x16 = makeRepeatString(08, 16)
109-
let repeatString16x08 = makeRepeatString(16, 08)
110-
let repeatString16x16 = makeRepeatString(16, 16)
98+
let arrayString08x08 = makeArrayString(08, 08)
99+
let arrayString08x16 = makeArrayString(08, 16)
100+
let arrayString16x08 = makeArrayString(16, 08)
101+
let arrayString16x16 = makeArrayString(16, 16)
111102

112103
@inline(never)
113-
public func with(
114-
_ collection: FlattenSequence<Repeated<String>>,
115-
_ iterations: Int
116-
) {
104+
public func with(_ collection: FlattenSequence<[String]>, _ iterations: Int) {
117105
var value = 0 as Int
118106

119107
for _ in 0 ..< iterations {

0 commit comments

Comments
 (0)