|
| 1 | +//===--- FlattenDistanceFromTo.swift --------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import TestsUtils |
| 14 | + |
| 15 | +public let FlattenDistanceFromTo = [ |
| 16 | + BenchmarkInfo( |
| 17 | + name: "FlattenDistanceFromTo.RandomAccess.16x16", |
| 18 | + runFunction: { withRandomAccess(16, 16, $0) }, |
| 19 | + tags: [.validation, .api]), |
| 20 | + |
| 21 | + BenchmarkInfo( |
| 22 | + name: "FlattenDistanceFromTo.RandomAccess.16x32", |
| 23 | + runFunction: { withRandomAccess(16, 32, $0) }, |
| 24 | + tags: [.validation, .api]), |
| 25 | + |
| 26 | + BenchmarkInfo( |
| 27 | + name: "FlattenDistanceFromTo.RandomAccess.32x16", |
| 28 | + runFunction: { withRandomAccess(32, 16, $0) }, |
| 29 | + tags: [.validation, .api]), |
| 30 | + |
| 31 | + BenchmarkInfo( |
| 32 | + name: "FlattenDistanceFromTo.RandomAccess.32x32", |
| 33 | + runFunction: { withRandomAccess(32, 32, $0) }, |
| 34 | + tags: [.validation, .api]), |
| 35 | +] |
| 36 | + |
| 37 | +@inline(never) |
| 38 | +public func withRandomAccess( |
| 39 | + _ outer: Int, |
| 40 | + _ inner: Int, |
| 41 | + _ iterations: Int |
| 42 | +) { |
| 43 | + 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 | + |
| 48 | + 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) |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + blackHole(value == 0) |
| 58 | +} |
0 commit comments