Created
September 28, 2018 15:03
-
-
Save Nyconing/f48fc4382cd2dc1d530da4c27f0e2d6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void Main() | |
{ | |
Console.ReadLine(); | |
Console.WriteLine("Hello, world!"); | |
Console.WriteLine("Usage: benchmark <filename>"); | |
string data = DataIsFuxxkingBig(); | |
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