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

1. Replaced occurrences of Repeated<T> with Array<T>.
This commit is contained in:
Oscar Byström Ericsson
2024-02-22 20:33:07 +01:00
parent dff27479bf
commit cef7c43daf

View File

@@ -14,73 +14,67 @@ import TestsUtils
public let FlattenDistanceFromTo = [
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.16x16",
runFunction: { with(randomAccess16x16, $0) },
name: "FlattenDistanceFromTo.Array.Array.16.16",
runFunction: { with(arrayArray16x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess16x16) }),
setUpFunction: { blackHole(arrayArray16x16) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.16x32",
runFunction: { with(randomAccess16x32, $0) },
name: "FlattenDistanceFromTo.Array.Array.16.32",
runFunction: { with(arrayArray16x32, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess16x32) }),
setUpFunction: { blackHole(arrayArray16x32) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.32x16",
runFunction: { with(randomAccess32x16, $0) },
name: "FlattenDistanceFromTo.Array.Array.32.16",
runFunction: { with(arrayArray32x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess32x16) }),
setUpFunction: { blackHole(arrayArray32x16) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RandomAccess.32x32",
runFunction: { with(randomAccess32x32, $0) },
name: "FlattenDistanceFromTo.Array.Array.32.32",
runFunction: { with(arrayArray32x32, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(randomAccess32x32) }),
setUpFunction: { blackHole(arrayArray32x32) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RepeatString.08x08",
runFunction: { with(repeatString08x08, $0) },
name: "FlattenDistanceFromTo.Array.String.08.08",
runFunction: { with(arrayString08x08, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(repeatString08x08) }),
setUpFunction: { blackHole(arrayString08x08) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RepeatString.08x16",
runFunction: { with(repeatString08x16, $0) },
name: "FlattenDistanceFromTo.Array.String.08.16",
runFunction: { with(arrayString08x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(repeatString08x16) }),
setUpFunction: { blackHole(arrayString08x16) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RepeatString.16x08",
runFunction: { with(repeatString16x08, $0) },
name: "FlattenDistanceFromTo.Array.String.16.08",
runFunction: { with(arrayString16x08, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(repeatString16x08) }),
setUpFunction: { blackHole(arrayString16x08) }),
BenchmarkInfo(
name: "FlattenDistanceFromTo.RepeatString.16x16",
runFunction: { with(repeatString16x16, $0) },
name: "FlattenDistanceFromTo.Array.String.16.16",
runFunction: { with(arrayString16x16, $0) },
tags: [.validation, .api],
setUpFunction: { blackHole(repeatString16x16) }),
setUpFunction: { blackHole(arrayString16x16) }),
]
// MARK: - Random Access
// MARK: - Array Array
func makeRandomAccess(
_ outer: Int,
_ inner: Int
) -> FlattenSequence<Repeated<Repeated<Int>>> {
repeatElement(repeatElement(0, count: inner), count: outer).joined()
func makeArrayArray(_ outer: Int, _ inner: Int) -> FlattenSequence<[[UInt8]]> {
Array(repeating: Array(repeating: 123, 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)
let arrayArray16x16 = makeArrayArray(16, 16)
let arrayArray16x32 = makeArrayArray(16, 32)
let arrayArray32x16 = makeArrayArray(32, 16)
let arrayArray32x32 = makeArrayArray(32, 32)
@inline(never)
public func with(
_ collection: FlattenSequence<Repeated<Repeated<Int>>>,
_ iterations: Int
) {
public func with(_ collection: FlattenSequence<[[UInt8]]>, _ iterations: Int) {
var value = 0 as Int
for _ in 0 ..< iterations {
@@ -95,25 +89,19 @@ public func with(
blackHole(value == 0)
}
// MARK: - Repeat String
// MARK: - Array String
func makeRepeatString(
_ outer: Int,
_ inner: Int
) -> FlattenSequence<Repeated<String>> {
repeatElement(String(repeating: "0", count: inner), count: outer).joined()
func makeArrayString(_ outer: Int, _ inner: Int) -> FlattenSequence<[String]> {
Array(repeating: String(repeating: "0", count: inner), count: outer).joined()
}
let repeatString08x08 = makeRepeatString(08, 08)
let repeatString08x16 = makeRepeatString(08, 16)
let repeatString16x08 = makeRepeatString(16, 08)
let repeatString16x16 = makeRepeatString(16, 16)
let arrayString08x08 = makeArrayString(08, 08)
let arrayString08x16 = makeArrayString(08, 16)
let arrayString16x08 = makeArrayString(16, 08)
let arrayString16x16 = makeArrayString(16, 16)
@inline(never)
public func with(
_ collection: FlattenSequence<Repeated<String>>,
_ iterations: Int
) {
public func with(_ collection: FlattenSequence<[String]>, _ iterations: Int) {
var value = 0 as Int
for _ in 0 ..< iterations {