fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var rxRTL = new Regex(@"[0-9]{4}", RegexOptions.Compiled | RegexOptions.RightToLeft);
  10. var rxLTR = new Regex(@"^.*([0-9]{4})", RegexOptions.Compiled);
  11. var rxRLTR = new Regex(@"^.*([0-9]{4})", RegexOptions.Compiled | RegexOptions.RightToLeft);
  12. var phrase = "Chocolatechipcookie2017!";
  13. Match m = null;
  14.  
  15. var stopwatch = new System.Diagnostics.Stopwatch();
  16. stopwatch.Start();
  17. for (int i=0; i<50000; i++) {
  18. m = rxRTL.Match(phrase);
  19. }
  20. stopwatch.Stop();
  21. Console.WriteLine("[0-9]{{4}} with RTL: Time spent: {0}; Match = {1}", stopwatch.Elapsed.TotalSeconds, m.Value);
  22.  
  23. var stopwatch1 = new System.Diagnostics.Stopwatch();
  24. stopwatch1.Start();
  25. for (int i=0; i<50000; i++) {
  26. m=rxLTR.Match(phrase);
  27. }
  28. stopwatch1.Stop();
  29. Console.WriteLine("^.*([0-9]{{4}}) no RTL modifier: Time spent: {0}; Match = {1}", stopwatch1.Elapsed.TotalSeconds, m.Groups[1].Value);
  30.  
  31. var stopwatch2 = new System.Diagnostics.Stopwatch();
  32. stopwatch2.Start();
  33. for (int i=0; i<50000; i++) {
  34. m=rxRLTR.Match(phrase);
  35. }
  36. stopwatch2.Stop();
  37. Console.WriteLine("^.*([0-9]{{4}}) with RTL modifier: Time spent: {0}; Match = {1}", stopwatch2.Elapsed.TotalSeconds, m.Groups[1].Value);
  38. }
  39. }
Success #stdin #stdout 0.11s 134208KB
stdin
Standard input is empty
stdout
[0-9]{4} with RTL: Time spent: 0.0202989; Match = 2017
^.*([0-9]{4}) no RTL modifier: Time spent: 0.0388398; Match = 2017
^.*([0-9]{4}) with RTL modifier: Time spent: 0.0236996; Match = 2017