fork(1) download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12.  
  13.  
  14. Random rand = new Random();
  15. Func<string> getRandString = // generates 128 random characters.
  16. () => Enumerable.Range(0, 128).Select(x => (char) rand.Next()).Aggregate("", (a, b) => a + b);
  17. Func<int> getRandInteger = () => rand.Next(); // generates random number.
  18. string format = "{0}({1}|{2})";
  19.  
  20. // Generate the big string.
  21. StringBuilder bigstr = new StringBuilder();
  22. for (int i = 0; i < 10; i++) // repeat 10 times.
  23. {
  24. bigstr.Append(string.Format(format, getRandString(), getRandInteger(), getRandInteger()));
  25. }
  26. string input = bigstr.ToString();
  27.  
  28. Regex testRegex = new Regex(@"\(([-|+]?\d+\|[-|+]?\d+?)\)");
  29. Stopwatch stopwatch = Stopwatch.StartNew();
  30. var matches = testRegex.Matches(input);
  31. var matchesCount = matches.Count;
  32. stopwatch.Stop();
  33. Console.WriteLine("Time Elapsed :\t{0}\nInputLength :\t{1}\nMatches Count :\t{2}", stopwatch.Elapsed, input.Length, matchesCount);
  34.  
  35.  
  36. }
  37. }
Success #stdin #stdout 0.12s 24408KB
stdin
Standard input is empty
stdout
Time Elapsed :	00:00:00.0129844
InputLength :	1502
Matches Count :	10