using System; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { Random rand = new Random(); Func getRandString = // generates 128 random characters. () => Enumerable.Range(0, 128).Select(x => (char) rand.Next()).Aggregate("", (a, b) => a + b); Func getRandInteger = () => rand.Next(); // generates random number. string format = "{0}({1}|{2})"; // Generate the big string. StringBuilder bigstr = new StringBuilder(); for (int i = 0; i < 10; i++) // repeat 10 times. { bigstr.Append(string.Format(format, getRandString(), getRandInteger(), getRandInteger())); } string input = bigstr.ToString(); Regex testRegex = new Regex(@"\(([-|+]?\d+\|[-|+]?\d+?)\)"); Stopwatch stopwatch = Stopwatch.StartNew(); var matches = testRegex.Matches(input); var matchesCount = matches.Count; stopwatch.Stop(); Console.WriteLine("Time Elapsed :\t{0}\nInputLength :\t{1}\nMatches Count :\t{2}", stopwatch.Elapsed, input.Length, matchesCount); } }