@@ -14,7 +14,7 @@ namespace System.Text.RegularExpressions.Tests
1414 public class Perf_Regex_Common
1515 {
1616 private Regex _email , _date , _ip , _uri ;
17- private Regex _searchWord , _searchWords , _searchSet , _searchBoundary ;
17+ private Regex _searchWord , _searchWords , _searchSet , _searchBoundary , _notOneLoopNodeBacktracking , _oneNodeBacktracking ;
1818 private string _loremIpsum ;
1919
2020 [ Params ( RegexOptions . None , RegexOptions . Compiled , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ]
@@ -32,9 +32,13 @@ public void Setup()
3232 _searchWords = new Regex ( @"tempus|magna|semper" , Options ) ;
3333 _searchSet = new Regex ( @"\w{10,}" , Options ) ;
3434 _searchBoundary = new Regex ( @"\b\w{10,}\b" , Options ) ;
35+ _notOneLoopNodeBacktracking = new Regex ( ".*(ss)" , Options ) ;
36+ _oneNodeBacktracking = new Regex ( @"[^a]+\.[^z]+" , Options ) ;
3537 _loremIpsum = LoremIpsum . ToString ( ) ;
3638 }
3739
40+ [ Benchmark ] public void Backtracking ( ) => _notOneLoopNodeBacktracking . Match ( "Essential services are provided by regular exprs." ) ;
41+ [ Benchmark ] public void OneNodeBacktracking ( ) => _oneNodeBacktracking . Match ( "This regex has the potential to be optimized further" ) ;
3842 [ Benchmark ] public void Email_IsMatch ( ) => _email . IsMatch ( "yay.performance@dot.net" ) ;
3943 [ Benchmark ] public void Email_IsNotMatch ( ) => _email . IsMatch ( "yay.performance@dot.net#" ) ;
4044
0 commit comments