Skip to content

Commit f4de0d6

Browse files
committed
[benchmark] StringMatch Legacy Factor
1 parent 256f609 commit f4de0d6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

benchmark/single-source/StringMatch.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import Darwin
2020
public let StringMatch = BenchmarkInfo(
2121
name: "StringMatch",
2222
runFunction: run_StringMatch,
23-
tags: [.validation, .api, .String])
23+
tags: [.validation, .api, .String],
24+
legacyFactor: 100)
2425

2526
/* match: search for regexp anywhere in text */
2627
func match(regexp: String, text: String) -> Bool {
2728
if regexp.first == "^" {
2829
return matchHere(regexp.dropFirst(), text[...])
2930
}
30-
31+
3132
var idx = text.startIndex
3233
while true { // must look even if string is empty
3334
if matchHere(regexp[...], text[idx..<text.endIndex]) {
@@ -37,7 +38,7 @@ func match(regexp: String, text: String) -> Bool {
3738
// do while sufficed in the original C version...
3839
text.formIndex(after: &idx)
3940
} // while idx++ != string.endIndex
40-
41+
4142
return false
4243
}
4344

@@ -46,19 +47,19 @@ func matchHere(_ regexp: Substring, _ text: Substring) -> Bool {
4647
if regexp.isEmpty {
4748
return true
4849
}
49-
50+
5051
if let c = regexp.first, regexp.dropFirst().first == "*" {
5152
return matchStar(c, regexp.dropFirst(2), text)
5253
}
53-
54+
5455
if regexp.first == "$" && regexp.dropFirst().isEmpty {
5556
return text.isEmpty
5657
}
57-
58+
5859
if let tc = text.first, let rc = regexp.first, rc == "." || tc == rc {
5960
return matchHere(regexp.dropFirst(), text.dropFirst())
6061
}
61-
62+
6263
return false
6364
}
6465

@@ -87,10 +88,9 @@ let tests: KeyValuePairs = [
8788

8889
@inline(never)
8990
public func run_StringMatch(_ N: Int) {
90-
for _ in 1...N*100 {
91+
for _ in 1...N {
9192
for (regex, text) in tests {
9293
_ = match(regexp: regex,text: text)
9394
}
9495
}
9596
}
96-

0 commit comments

Comments
 (0)