mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
FlattenSequence/distance(from:to:) benchmarks (v3).
1. Parameterized benchmark dependencies, per code review.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user