Skip to content

Commit 43b9032

Browse files
committed
Benchmark: Add not-found and all-found path variants
1 parent ce9d3b9 commit 43b9032

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

Sources/RegexBenchmark/Inputs/FSPaths.swift

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Successful match FSPaths
2-
private let fsPathSuccess = #"""
2+
private let pathSuccess = #"""
33
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionLeft
44
./First/Second/Third/some/really/long/content.extension/more/stuff/OptionRight
55
./First/Second/PrefixThird/some/really/long/content.extension/more/stuff/OptionLeft
@@ -10,7 +10,7 @@ private let fsPathSuccess = #"""
1010
//
1111
// We will have far more failures than successful matches by interspersing
1212
// this whole list between each success
13-
private let fsPathFailure = #"""
13+
private let pathFailure = #"""
1414
a/b/c
1515
/smol/path
1616
/a/really/long/path/that/is/certainly/stored/out/of/line
@@ -28,24 +28,43 @@ a/b/c
2828
./First/Second/PrefixThird/some/really/long/content/more/stuff/OptionRight
2929
"""#
3030

31+
private func listify(_ s: String) -> [String] {
32+
s.split(whereSeparator: { $0.isNewline }).map { String($0) }
33+
}
34+
35+
private let pathSuccessList: [String] = { listify(pathSuccess) }()
36+
private let pathFailureList: [String] = { listify(pathFailure) }()
37+
38+
private func scale(_ input: [String]) -> [String] {
39+
let threshold = 1_000
40+
var result = input
41+
while result.count < threshold {
42+
result.append(contentsOf: input)
43+
}
44+
return result
45+
}
46+
3147
extension Inputs {
3248
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)
49+
var result = pathFailureList
50+
result.append(contentsOf: pathFailureList)
3651

37-
for success in fsPathSuccess.split(whereSeparator: { $0.isNewline }) {
52+
for success in pathSuccessList {
3853
result.append(String(success))
39-
result.append(contentsOf: failures)
54+
result.append(contentsOf: pathFailureList)
55+
result.append(contentsOf: pathFailureList)
4056
}
4157

4258
// 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)
59+
return scale(result)
60+
61+
}()
4762

48-
return result
63+
static let fsPathsNotFoundList: [String] = {
64+
scale(pathFailureList)
65+
}()
4966

67+
static let fsPathsFoundList: [String] = {
68+
scale(pathFailureList)
5069
}()
5170
}

Sources/RegexBenchmark/Suite/FSPathsRegex.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@ extension BenchmarkRunner {
55
mutating func addFSPathsRegex() {
66
let fsPathsRegex =
77
#"^\./First/Second/(Prefix)?Third/.*\.extension/.*(OptionLeft|OptionRight)$"#
8-
let paths = CrossInputListBenchmark(
8+
9+
CrossInputListBenchmark(
910
baseName: "FSPathsRegex",
1011
regex: fsPathsRegex,
1112
inputs: Inputs.fsPathsList
12-
)
13-
paths.register(&self)
13+
).register(&self)
14+
15+
CrossInputListBenchmark(
16+
baseName: "FSPathsRegexNotFound",
17+
regex: fsPathsRegex,
18+
inputs: Inputs.fsPathsNotFoundList
19+
).register(&self)
20+
21+
CrossInputListBenchmark(
22+
baseName: "FSPathsRegexFound",
23+
regex: fsPathsRegex,
24+
inputs: Inputs.fsPathsFoundList
25+
).register(&self)
26+
1427
}
1528
}
1629

0 commit comments

Comments
 (0)