- Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathBenchmark.cs
40 lines (31 loc) · 1.14 KB
/
Benchmark.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
usingSystem;
usingSystem.IO;
usingSystem.Text.RegularExpressions;
usingSystem.Diagnostics;
classBenchmark
{
staticvoidMain(string[]args)
{
if(args.Length!=1)
{
Console.WriteLine("Usage: benchmark <filename>");
Environment.Exit(1);
}
StreamReaderreader=newSystem.IO.StreamReader(args[0]);
stringdata=reader.ReadToEnd();
// Email
Benchmark.Measure(data,@"[\w\.+-]+@[\w\.-]+\.[\w\.-]+");
// URI
Benchmark.Measure(data,@"[\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?");
// IP
Benchmark.Measure(data,@"(?:(?: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])");
}
staticvoidMeasure(stringdata,stringpattern)
{
Stopwatchstopwatch=Stopwatch.StartNew();
MatchCollectionmatches=Regex.Matches(data,pattern,RegexOptions.Compiled);
intcount=matches.Count;
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds.ToString("G",System.Globalization.CultureInfo.InvariantCulture)+" - "+count);
}
}