Skip to content

Instantly share code, notes, and snippets.

@Nyconing
Created September 28, 2018 15:03
Show Gist options
  • Save Nyconing/f48fc4382cd2dc1d530da4c27f0e2d6e to your computer and use it in GitHub Desktop.
Save Nyconing/f48fc4382cd2dc1d530da4c27f0e2d6e to your computer and use it in GitHub Desktop.
private static void Main()
{
Console.ReadLine();
Console.WriteLine("Hello, world!");
Console.WriteLine("Usage: benchmark <filename>");
string data = DataIsFuxxkingBig();
// Email
Measure(data, new Regex(@"[\w\.+-]+@[\w\.-]+\.[\w\.-]+", RegexOptions.Compiled) );
// URI
Measure(data, new Regex(@"[\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?", RegexOptions.Compiled) );
// IP
Measure(data, new Regex(@"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])", RegexOptions.Compiled) );
Console.ReadLine();
}
static void Measure(string data, Regex pattern)
{
Stopwatch stopwatch = Stopwatch.StartNew();
MatchCollection matches = pattern.Matches(data);
int count = matches.Count;
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds.ToString("G", System.Globalization.CultureInfo.InvariantCulture) + " - " + count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment