Skip to content

Commit d10a14a

Browse files
committed
Benchmark: add a path-filtering benchmark (#786)
1 parent 2442083 commit d10a14a

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Sources/RegexBenchmark/BenchmarkRegistration.swift

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extension BenchmarkRunner {
2020
self.addIpAddress()
2121

2222
self.addURLWithWordBoundaries()
23+
self.addFSPathsRegex()
2324
// -- end of registrations --
2425
}
2526
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Successful match FSPaths
2+
private let fsPathSuccess = #"""
3+
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionLeft
4+
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionRight
5+
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionLeft
6+
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionRight
7+
"""#
8+
9+
// Unsucessful match FSPaths.
10+
//
11+
// We will have far more failures than successful matches by interspersing
12+
// this whole list between each success
13+
private let fsPathFailure = #"""
14+
a/b/c
15+
/smol/path
16+
/a/really/long/path/that/is/certainly/stored/out/of/line
17+
./First/Second/Third/some/really/long/content.extension/more/stuff/NothingToSeeHere
18+
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/NothingToSeeHere
19+
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionNeither
20+
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionNeither
21+
/First/Second/Third/some/really/long/content.extension/more/stuff/OptionLeft
22+
/First/Second/Third/some/really/long/content.extension/more/stuff/OptionRight
23+
/First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionLeft
24+
/First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionRight
25+
./First/Second/Third/some/really/long/content/more/stuff/OptionLeft
26+
./First/Second/Third/some/really/long/content/more/stuff/OptionRight
27+
./First/Second/PrefixThird/some/really/long/content/more/stuff/OptionLeft
28+
./First/Second/PrefixThird/some/really/long/content/more/stuff/OptionRight
29+
"""#
30+
31+
extension Inputs {
32+
static let fsPathsList: [String] = {
33+
var result: [String] = []
34+
let failures: [String] = fsPathFailure.split(whereSeparator: { $0.isNewline }).map { String($0) }
35+
result.append(contentsOf: failures)
36+
37+
for success in fsPathSuccess.split(whereSeparator: { $0.isNewline }) {
38+
result.append(String(success))
39+
result.append(contentsOf: failures)
40+
}
41+
42+
// Scale result up a bit
43+
result.append(contentsOf: result)
44+
result.append(contentsOf: result)
45+
result.append(contentsOf: result)
46+
result.append(contentsOf: result)
47+
48+
return result
49+
50+
}()
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import _StringProcessing
2+
3+
4+
extension BenchmarkRunner {
5+
mutating func addFSPathsRegex() {
6+
let fsPathsRegex =
7+
#"^\./First/Second/(Prefix)?Third/.*\.extension/.*(OptionLeft|OptionRight)$"#
8+
let paths = CrossInputListBenchmark(
9+
baseName: "FSPathsRegex",
10+
regex: fsPathsRegex,
11+
inputs: Inputs.fsPathsList
12+
)
13+
paths.register(&self)
14+
}
15+
}
16+

0 commit comments

Comments
 (0)