Skip to content

Add benchmarks for Substring.dropFirst(_:) and dropLast(_:) #32473

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
merged 2 commits into from
Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions benchmark/single-source/Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public let SubstringTest = [
BenchmarkInfo(name: "EqualSubstringString", runFunction: run_EqualSubstringString, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "EqualSubstringSubstring", runFunction: run_EqualSubstringSubstring, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "EqualSubstringSubstringGenericEquatable", runFunction: run_EqualSubstringSubstringGenericEquatable, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "SubstringDropFirst1", runFunction: run_SubstringDropFirst1, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "SubstringDropLast1", runFunction: run_SubstringDropLast1, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "LessSubstringSubstring", runFunction: run_LessSubstringSubstring, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "LessSubstringSubstringGenericComparable", runFunction: run_LessSubstringSubstringGenericComparable, tags: [.validation, .api, .String]),
BenchmarkInfo(name: "StringFromLongWholeSubstring", runFunction: run_StringFromLongWholeSubstring, tags: [.validation, .api, .String]),
Expand All @@ -34,6 +36,8 @@ let longWide = "fὢasὢodὢijὢadὢolὢsjὢalὢsdὢjlὢasὢdfὢijὢ
let (s1, ss1) = equivalentWithDistinctBuffers()
let (s2, ss2) = equivalentWithDistinctBuffers()

let quiteLong = String(repeating: "0", count: 15_000)[...]

@inline(never)
public func run_SubstringFromLongString(_ N: Int) {
var s = longWide
Expand Down Expand Up @@ -126,6 +130,22 @@ public func run_EqualSubstringSubstringGenericEquatable(_ N: Int) {
}
}

@inline(never)
public func run_SubstringDropFirst1(_ N: Int) {
let s = quiteLong
for _ in 1...N*1000 {
blackHole(!s.dropFirst(1).isEmpty)
}
}

@inline(never)
public func run_SubstringDropLast1(_ N: Int) {
let s = quiteLong
for _ in 1...N*1000 {
blackHole(!s.dropLast(1).isEmpty)
}
}

/*
func checkEqual<T, U>(_ x: T, _ y: U)
where T : StringProtocol, U : StringProtocol {
Expand Down