Skip to content

Benchmark: add a path-sorting benchmark #786

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 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Sources/RegexBenchmark/BenchmarkRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension BenchmarkRunner {
self.addIpAddress()

self.addURLWithWordBoundaries()
self.addFSPathsRegex()
// -- end of registrations --
}
}
51 changes: 51 additions & 0 deletions Sources/RegexBenchmark/Inputs/FSPaths.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Successful match FSPaths
private let fsPathSuccess = #"""
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionLeft
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionRight
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionLeft
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionRight
"""#

// Unsucessful match FSPaths.
//
// We will have far more failures than successful matches by interspersing
// this whole list between each success
private let fsPathFailure = #"""
a/b/c
/smol/path
/a/really/long/path/that/is/certainly/stored/out/of/line
./First/Second/Third/some/really/long/content.extension/more/stuff/NothingToSeeHere
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/NothingToSeeHere
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionNeither
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionNeither
/First/Second/Third/some/really/long/content.extension/more/stuff/OptionLeft
/First/Second/Third/some/really/long/content.extension/more/stuff/OptionRight
/First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionLeft
/First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionRight
./First/Second/Third/some/really/long/content/more/stuff/OptionLeft
./First/Second/Third/some/really/long/content/more/stuff/OptionRight
./First/Second/PrefixThird/some/really/long/content/more/stuff/OptionLeft
./First/Second/PrefixThird/some/really/long/content/more/stuff/OptionRight
"""#

extension Inputs {
static let fsPathsList: [String] = {
var result: [String] = []
let failures: [String] = fsPathFailure.split(whereSeparator: { $0.isNewline }).map { String($0) }
result.append(contentsOf: failures)

for success in fsPathSuccess.split(whereSeparator: { $0.isNewline }) {
result.append(String(success))
result.append(contentsOf: failures)
}

// Scale result up a bit
result.append(contentsOf: result)
result.append(contentsOf: result)
result.append(contentsOf: result)
result.append(contentsOf: result)

return result

}()
}
16 changes: 16 additions & 0 deletions Sources/RegexBenchmark/Suite/FSPathsRegex.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import _StringProcessing


extension BenchmarkRunner {
mutating func addFSPathsRegex() {
let fsPathsRegex =
#"^\./First/Second/(Prefix)?Third/.*\.extension/.*(OptionLeft|OptionRight)$"#
let paths = CrossInputListBenchmark(
baseName: "FSPathsRegex",
regex: fsPathsRegex,
inputs: Inputs.fsPathsList
)
paths.register(&self)
}
}