-
Notifications
You must be signed in to change notification settings - Fork 10.5k
FlattenSequence/distance(from:to:) benchmarks. #71786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
glessard
merged 7 commits into
swiftlang:main
from
oscbyspro:better-joined-distance-from-to-benchmarks
Feb 25, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ea8985
FlattenSequence/distance(from:to:) benchmarks (#71648).
oscbyspro e6cc57f
FlattenSequence/distance(from:to:) benchmarks (v2).
oscbyspro 6829f80
FlattenSequence/distance(from:to:) benchmarks (v3).
oscbyspro dff2747
FlattenSequence/distance(from:to:) benchmarks (v4).
oscbyspro cef7c43
FlattenSequence/distance(from:to:) benchmarks (v5).
oscbyspro 7ecb987
FlattenSequence/distance(from:to:) benchmarks (v6).
oscbyspro 8cfbb62
FlattenSequence/distance(from:to:) benchmarks (v7).
oscbyspro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//===--- FlattenDistanceFromTo.swift --------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import TestsUtils | ||
|
||
public let benchmarks = [ | ||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.Array.04.04", | ||
runFunction: { with(arrayArray04x04, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayArray04x04) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.Array.04x08", | ||
runFunction: { with(arrayArray04x08, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayArray04x08) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.Array.08.04", | ||
runFunction: { with(arrayArray08x04, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayArray08x04) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.Array.08.08", | ||
runFunction: { with(arrayArray08x08, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayArray08x08) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.String.04.04", | ||
runFunction: { with(arrayString04x04, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayString04x04) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.String.04.08", | ||
runFunction: { with(arrayString04x08, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayString04x08) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.String.08.04", | ||
runFunction: { with(arrayString08x04, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayString08x04) }), | ||
|
||
BenchmarkInfo( | ||
name: "FlattenDistanceFromTo.Array.String.08.08", | ||
runFunction: { with(arrayString08x08, $0) }, | ||
tags: [.validation, .api], | ||
setUpFunction: { blackHole(arrayString08x08) }), | ||
] | ||
|
||
// MARK: - Array Array | ||
|
||
func makeArrayArray(_ outer: Int, _ inner: Int) -> FlattenSequence<[[UInt8]]> { | ||
Array(repeating: Array(repeating: 123, count: inner), count: outer).joined() | ||
} | ||
|
||
let arrayArray04x04 = makeArrayArray(04, 04) | ||
let arrayArray04x08 = makeArrayArray(04, 08) | ||
let arrayArray08x04 = makeArrayArray(08, 04) | ||
let arrayArray08x08 = makeArrayArray(08, 08) | ||
|
||
@inline(never) | ||
public func with(_ collection: FlattenSequence<[[UInt8]]>, _ iterations: Int) { | ||
var value = 0 as Int | ||
|
||
for _ in 0 ..< iterations { | ||
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) | ||
} | ||
|
||
// MARK: - Array String | ||
|
||
func makeArrayString(_ outer: Int, _ inner: Int) -> FlattenSequence<[String]> { | ||
Array(repeating: String(repeating: "0", count: inner), count: outer).joined() | ||
} | ||
|
||
let arrayString04x04 = makeArrayString(04, 04) | ||
let arrayString04x08 = makeArrayString(04, 08) | ||
let arrayString08x04 = makeArrayString(08, 04) | ||
let arrayString08x08 = makeArrayString(08, 08) | ||
|
||
@inline(never) | ||
public func with(_ collection: FlattenSequence<[String]>, _ iterations: Int) { | ||
var value = 0 as Int | ||
|
||
for _ in 0 ..< iterations { | ||
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) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add
register(FlattenDistanceFromTo.benchmarks)
at line 286 below.With the PR as-is the benchmark runner still does not know about this addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. The script could use some love too: