File tree Expand file tree Collapse file tree 5 files changed +41
-17
lines changed Expand file tree Collapse file tree 5 files changed +41
-17
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,13 @@ public struct Benchmark: RegexBenchmark {
15
15
public enum MatchType {
16
16
case whole
17
17
case first
18
- case enumerate
18
+ case allMatches
19
19
}
20
20
21
21
public func run( ) {
22
22
switch ty {
23
23
case . whole: blackHole ( target. wholeMatch ( of: regex) )
24
- case . enumerate : blackHole ( target. matches ( of: regex) )
24
+ case . allMatches : blackHole ( target. matches ( of: regex) )
25
25
case . first: blackHole ( target. firstMatch ( of: regex) )
26
26
}
27
27
}
@@ -54,14 +54,14 @@ public struct BenchmarkRunner {
54
54
// Register instances of Benchmark and run them
55
55
let suiteName : String
56
56
var suite : [ any RegexBenchmark ]
57
- let samples : Int = 40
57
+ let samples : Int = 20
58
58
59
59
public init ( suiteName: String ) {
60
60
self . suiteName = suiteName
61
61
self . suite = [ ]
62
62
}
63
63
64
- public mutating func register( new: some RegexBenchmark ) {
64
+ public mutating func register( _ new: some RegexBenchmark ) {
65
65
suite. append ( new)
66
66
}
67
67
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ extension BenchmarkRunner {
12
12
let basicBacktrack = Benchmark (
13
13
name: " BasicBacktrack " ,
14
14
regex: try ! Regex ( r) ,
15
- ty: . enumerate ,
15
+ ty: . allMatches ,
16
16
target: s
17
17
)
18
18
@@ -37,9 +37,9 @@ extension BenchmarkRunner {
37
37
target: s
38
38
)
39
39
40
- register ( new : basicBacktrack)
41
- register ( new : basicBacktrackNS)
42
- register ( new : basicBacktrackFirstMatch)
43
- register ( new : basicBacktrackNSFirstMatch)
40
+ register ( basicBacktrack)
41
+ register ( basicBacktrackNS)
42
+ register ( basicBacktrackFirstMatch)
43
+ register ( basicBacktrackNSFirstMatch)
44
44
}
45
45
}
Original file line number Diff line number Diff line change @@ -1656,7 +1656,7 @@ extension BenchmarkRunner {
1656
1656
let cssRegex = Benchmark (
1657
1657
name: " cssRegex " ,
1658
1658
regex: try ! Regex ( r) ,
1659
- ty: . enumerate ,
1659
+ ty: . allMatches ,
1660
1660
target: css
1661
1661
)
1662
1662
@@ -1666,7 +1666,7 @@ extension BenchmarkRunner {
1666
1666
ty: . all,
1667
1667
target: css
1668
1668
)
1669
- register ( new : cssRegex)
1670
- register ( new : cssRegexNS)
1669
+ register ( cssRegex)
1670
+ register ( cssRegexNS)
1671
1671
}
1672
1672
}
Original file line number Diff line number Diff line change @@ -6,20 +6,44 @@ extension BenchmarkRunner {
6
6
let r = " a "
7
7
let s = String ( repeating: " " , count: 100000 )
8
8
9
+ // this does nothing but loop through the loop in
10
+ // Match.swift (Regex._firstMatch) since the engine should fail right away,
9
11
let firstMatch = Benchmark (
10
12
name: " FirstMatch " ,
11
13
regex: try ! Regex ( r) ,
12
14
ty: . first,
13
15
target: s
14
16
)
17
+
18
+ // a comparison with now NSRegularExpression handles this situation
15
19
let firstMatchNS = NSBenchmark (
16
20
name: " FirstMatchNS " ,
17
21
regex: try ! NSRegularExpression ( pattern: r) ,
18
22
ty: . first,
19
23
target: s
20
24
)
21
25
22
- register ( new: firstMatch)
23
- register ( new: firstMatchNS)
26
+ let s2 = String ( repeating: " a " , count: 10000 )
27
+
28
+ // matches calls into firstMatch, so really they're the same
29
+ // this also stress tests the captures
30
+ let allMatches = Benchmark (
31
+ name: " AllMatches " ,
32
+ regex: try ! Regex ( r) ,
33
+ ty: . allMatches,
34
+ target: s2
35
+ )
36
+
37
+ let allMatchesNS = NSBenchmark (
38
+ name: " AllMatchesNS " ,
39
+ regex: try ! NSRegularExpression ( pattern: r) ,
40
+ ty: . all,
41
+ target: s2
42
+ )
43
+
44
+ register ( firstMatch)
45
+ register ( firstMatchNS)
46
+ register ( allMatches)
47
+ register ( allMatchesNS)
24
48
}
25
49
}
Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ extension BenchmarkRunner {
34
34
target: String ( repeating: " a " , count: size) + " ; "
35
35
)
36
36
37
- register ( new : reluctantQuant)
38
- register ( new : reluctantQuantWithTerminal)
39
- register ( new : eagarQuantWithTerminal)
37
+ register ( reluctantQuant)
38
+ register ( reluctantQuantWithTerminal)
39
+ register ( eagarQuantWithTerminal)
40
40
}
41
41
}
You can’t perform that action at this time.
0 commit comments