Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Text.RegularExpressions;
- using System.Threading;
- namespace Testbed
- {
- class Program
- {
- static void Main(string[] args)
- {
- Thread t = new Thread(() =>
- {
- // Common stuff for quick benchmarking
- Stopwatch sw = new Stopwatch();
- int maxNum = 1000;
- maxNum++;
- string regex;
- string test;
- for (int num = 1; num < maxNum; num++)
- {
- regex = "(a?){" + num + "}a{" + num + "}";
- test = "";
- for (int i = 0; i < num; i++)
- {
- test += "a";
- }
- try
- {
- Console.Write("num = {0}:\t", num);
- sw.Start();
- Regex.Match(test, regex, RegexOptions.None, TimeSpan.FromSeconds(30));
- sw.Stop();
- Console.WriteLine("{0} ms", sw.Elapsed.TotalMilliseconds);
- }
- catch (RegexMatchTimeoutException)
- {
- Console.WriteLine("Match timeout");
- break;
- }
- finally
- {
- sw.Reset();
- }
- }
- });
- t.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement