11import Foundation
22
3+ protocol Debug {
4+ func debug( )
5+ }
6+
7+ extension Debug {
8+ var maxStringLengthForPrint : Int { 1000 }
9+ var maxMatchCountForPrint : Int { 100 }
10+ }
11+
312extension Benchmark {
413 func debug( ) {
514 switch type {
615 case . whole:
716 let result = target. wholeMatch ( of: regex)
817 if let match = result {
9- if match. 0 . count > 1000 {
18+ if match. 0 . count > maxStringLengthForPrint {
1019 print ( " - Match: len = \( match. 0 . count) " )
1120 } else {
1221 print ( " - Match: \( match. 0 ) " )
@@ -22,7 +31,7 @@ extension Benchmark {
2231 }
2332
2433 print ( " - Total matches: \( results. count) " )
25- if results. count > 100 {
34+ if results. count > maxMatchCountForPrint {
2635 print ( " # Too many matches, not printing " )
2736 let avgLen = results. map ( { result in String ( target [ result. range] ) . count} )
2837 . reduce ( 0.0 , { $0 + Double( $1) } ) / Double( results. count)
@@ -32,7 +41,7 @@ extension Benchmark {
3241 }
3342
3443 for match in results {
35- if match. 0 . count > 1000 {
44+ if match. 0 . count > maxStringLengthForPrint {
3645 print ( " - Match: len = \( match. 0 . count) " )
3746 } else {
3847 print ( " - Match: \( match. 0 ) " )
@@ -42,7 +51,7 @@ extension Benchmark {
4251 case . first:
4352 let result = target. firstMatch ( of: regex)
4453 if let match = result {
45- if match. 0 . count > 1000 {
54+ if match. 0 . count > maxStringLengthForPrint {
4655 print ( " - Match: len = \( match. 0 . count) " )
4756 } else {
4857 print ( " - Match: \( match. 0 ) " )
@@ -56,6 +65,7 @@ extension Benchmark {
5665}
5766
5867extension NSBenchmark {
68+
5969 func debug( ) {
6070 switch type {
6171 case . allMatches:
@@ -66,13 +76,13 @@ extension NSBenchmark {
6676 }
6777
6878 print ( " - Total matches: \( results. count) " )
69- if results. count > 100 {
79+ if results. count > maxMatchCountForPrint {
7080 print ( " # Too many matches, not printing " )
7181 return
7282 }
7383
7484 for m in results {
75- if m. range. length > 1000 {
85+ if m. range. length > maxStringLengthForPrint {
7686 print ( " - Match: len = \( m. range. length) " )
7787 } else {
7888 print ( " - Match: \( target [ Range ( m. range, in: target) !] ) " )
@@ -81,7 +91,7 @@ extension NSBenchmark {
8191 case . first:
8292 let result = regex. firstMatch ( in: target, range: range)
8393 if let match = result {
84- if match. range. length > 1000 {
94+ if match. range. length > maxStringLengthForPrint {
8595 print ( " - Match: len = \( match. range. length) " )
8696 } else {
8797 print ( " - Match: \( target [ Range ( match. range, in: target) !] ) " )
0 commit comments