FlattenSequence/distance(from:to:) benchmarks (v3).

1. Parameterized benchmark dependencies, per code review.
This commit is contained in:
Oscar Byström Ericsson
2024-02-22 17:25:29 +01:00
parent e6cc57f321
commit 6829f808a0

View File

@@ -15,44 +15,58 @@ import TestsUtils
public let FlattenDistanceFromTo = [
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.16x16",
runFunction: { withRandomAccess(16, 16, $0) },
tags: [.validation, .api]),
runFunction: { with(randomAccess16x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess16x16) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.16x32",
runFunction: { withRandomAccess(16, 32, $0) },
tags: [.validation, .api]),
runFunction: { with(randomAccess16x32, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess16x32) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.32x16",
runFunction: { withRandomAccess(32, 16, $0) },
tags: [.validation, .api]),
runFunction: { with(randomAccess32x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess32x16) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.32x32",
runFunction: { withRandomAccess(32, 32, $0) },
tags: [.validation, .api]),
runFunction: { with(randomAccess32x32, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess32x32) }),
]
@inline(never)
public func withRandomAccess(
// MARK: - Random Access
func makeRandomAccess(
_ outer: Int,
_ inner: Int,
_ inner: Int
) -> FlattenSequence<Repeated<Repeated<Int>>> {
repeatElement(repeatElement(0, count: inner), count: outer).joined()
}
let randomAccess16x16 = makeRandomAccess(16, 16)
let randomAccess16x32 = makeRandomAccess(16, 32)
let randomAccess32x16 = makeRandomAccess(32, 16)
let randomAccess32x32 = makeRandomAccess(32, 32)
@inline(never)
public func with(
_ collection: FlattenSequence<Repeated<Repeated<Int>>>,
_ iterations: Int
) {
var value = 0 as Int
let minor = repeatElement(00000, count: inner)
let major = repeatElement(minor, count: outer)
let flattened: FlattenSequence = major.joined()
for _ in 0 ..< iterations {
for a in flattened.indices {
for b in flattened.indices {
value &+= flattened.distance(from: a, to: b)
value &+= flattened.distance(from: b, to: a)
for a in collection.indices {
for b in collection.indices {
value &+= collection.distance(from: a, to: b)
value &+= collection.distance(from: b, to: a)
}
}
}
blackHole(value == 0)
}