Skip to content
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