diff --git a/Sources/RegexBenchmark/BenchmarkRegistration.swift b/Sources/RegexBenchmark/BenchmarkRegistration.swift index e12502e9..a812b84b 100644 --- a/Sources/RegexBenchmark/BenchmarkRegistration.swift +++ b/Sources/RegexBenchmark/BenchmarkRegistration.swift @@ -20,6 +20,7 @@ extension BenchmarkRunner { self.addIpAddress() self.addURLWithWordBoundaries() + self.addFSPathsRegex() // -- end of registrations -- } } diff --git a/Sources/RegexBenchmark/Inputs/FSPaths.swift b/Sources/RegexBenchmark/Inputs/FSPaths.swift new file mode 100644 index 00000000..a2537c59 --- /dev/null +++ b/Sources/RegexBenchmark/Inputs/FSPaths.swift @@ -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 + + }() +} diff --git a/Sources/RegexBenchmark/Suite/FSPathsRegex.swift b/Sources/RegexBenchmark/Suite/FSPathsRegex.swift new file mode 100644 index 00000000..a0bf8f35 --- /dev/null +++ b/Sources/RegexBenchmark/Suite/FSPathsRegex.swift @@ -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) + } +} +