@@ -3,33 +3,40 @@ import Foundation
33
44protocol RegexBenchmark {
55 var name : String { get }
6- mutating func compile( )
76 func run( )
87 func debug( )
98}
109
11- struct Benchmark : RegexBenchmark {
12- let name : String
13- var regex : Regex < AnyRegexOutput >
14- let type : MatchType
15- let target : String
10+ protocol SwiftRegexBenchmark : RegexBenchmark {
11+ var regex : Regex < AnyRegexOutput > { get set }
12+ mutating func compile( )
13+ mutating func enableTracing( )
14+ mutating func enableMetrics( )
15+ }
1616
17- enum MatchType {
18- case whole
19- case first
20- case allMatches
21- }
22-
17+ extension SwiftRegexBenchmark {
2318 mutating func compile( ) {
2419 let _ = regex. _forceAction ( . recompile)
2520 }
26-
2721 mutating func enableTracing( ) {
2822 let _ = regex. _forceAction ( . addOptions( . enableTracing) )
2923 }
3024 mutating func enableMetrics( ) {
3125 let _ = regex. _forceAction ( . addOptions( [ . enableMetrics, . disableOptimizations] ) )
3226 }
27+ }
28+
29+ struct Benchmark : SwiftRegexBenchmark {
30+ let name : String
31+ var regex : Regex < AnyRegexOutput >
32+ let type : MatchType
33+ let target : String
34+
35+ enum MatchType {
36+ case whole
37+ case first
38+ case allMatches
39+ }
3340
3441 func run( ) {
3542 switch type {
@@ -55,9 +62,6 @@ struct NSBenchmark: RegexBenchmark {
5562 case first
5663 }
5764
58- // Not measured for NSRegularExpression
59- mutating func compile( ) { }
60-
6165 func run( ) {
6266 switch type {
6367 case . allMatches: blackHole ( regex. matches ( in: target, range: range) )
@@ -67,20 +71,10 @@ struct NSBenchmark: RegexBenchmark {
6771}
6872
6973/// A benchmark running a regex on strings in input set
70- struct InputListBenchmark : RegexBenchmark {
74+ struct InputListBenchmark : SwiftRegexBenchmark {
7175 let name : String
7276 var regex : Regex < AnyRegexOutput >
7377 let targets : [ String ]
74-
75- mutating func compile( ) {
76- blackHole ( regex. _forceAction ( . recompile) )
77- }
78- mutating func enableTracing( ) {
79- let _ = regex. _forceAction ( . addOptions( . enableTracing) )
80- }
81- mutating func enableMetrics( ) {
82- let _ = regex. _forceAction ( . addOptions( . enableMetrics) )
83- }
8478
8579 func run( ) {
8680 for target in targets {
@@ -103,8 +97,6 @@ struct InputListNSBenchmark: RegexBenchmark {
10397 func range( in target: String ) -> NSRange {
10498 NSRange ( target. startIndex..< target. endIndex, in: target)
10599 }
106-
107- mutating func compile( ) { }
108100
109101 func run( ) {
110102 for target in targets {
0 commit comments