Beispiel #1
0
        public static void VeryLongMatches()
        {
            const int times = 1, inputLength = 1000000;

            string alphabet       = "abcdefghijklmnopqrstuvwxyz";
            string lowercaseChars = EnumerablePerformanceTests.RepeatChars(alphabet, inputLength)
                                    .AsString();

            //Console.WriteLine("(Short input)");
            //testRegexMatches("x", @".", times);
            //// 0.171 sec.

            testRegexMatches(lowercaseChars, @"", times);
            //  2.138 sec. (inputLength =  1,000,000)
            // 37.968 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"k", times);
            //  2.907 sec. (inputLength =  1,000,000)
            // 30.292 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"\w", times);
            //  8.315 sec. (inputLength =  1,000,000)   (!?)
            // 16.459 sec. (inputLength =  2,000,000)
            // 25.295 sec. (inputLength =  3,000,000)
            // 41.248 sec. (inputLength =  5,000,000)
            // 83.437 sec. (inputLength = 10,000,000)   (64 bytes/match)

            testRegexMatches(lowercaseChars, @"\w{1000}", times);
            //  0.669 sec. (inputLength =  1,000,000)
            //  6.272 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"(\w{1000})+", times);
            //  0.857 sec. (inputLength =  1,000,000)
            //  9.044 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"(\w{10000})+", times);
            //  0.898 sec. (inputLength =  1,000,000)
            //  9.242 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"(\w{20000})+", times);
            //  1.173 sec. (inputLength =  1,000,000)
            // 12.828 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"(\w{100000})+", times);
            //  1.288 sec. (inputLength =  1,000,000)
            // 13.453 sec. (inputLength = 10,000,000)

            testRegexMatches(lowercaseChars, @"(\w{10001})+", times);
            // 12.556 sec. (inputLength =  1,000,000)   (!?)
            // 18.828 sec. (inputLength = 10,000,000)


            testRegexMatches(lowercaseChars, alphabet, times);

            testRegexMatches(lowercaseChars, alphabet.Substring(0, alphabet.Length / 2), times);

            testRegexMatches(lowercaseChars, string.Format("({0})+", alphabet), times);

            testRegexMatches(lowercaseChars, @"\w{1000000}", times);

            testRegexMatches(lowercaseChars, @"\w+", times);

            testRegexMatches(lowercaseChars, @"\w+n", times);

            testRegexMatches(lowercaseChars, @"\w+e", times);

            testRegexMatches(lowercaseChars + "7", @"\w+7", times);

            testRegexMatches(lowercaseChars + "7", @"\w+?7", times);


            testRegexMatches(lowercaseChars, alphabet.ToUpper(), times);

            testRegexMatches(lowercaseChars, alphabet.ToUpper(), RegexOptions.IgnoreCase, times);

            testRegexMatches(lowercaseChars, alphabet.Substring(0, alphabet.Length / 2).ToUpper(), RegexOptions.IgnoreCase, times);

            testRegexMatches(lowercaseChars, @"[a-m]+", times);

            testRegexMatches(lowercaseChars, @"[A-M]+", RegexOptions.IgnoreCase, times);


            testRegexMatches(lowercaseChars, @"(\w{1,100000})+", times);

            testRegexMatches(lowercaseChars, @"(\w{1,1000000})+", times);
        }
        public static void CharClassPatternTest()
        {
            const int times = 200, maxItemCount = 100000;


            string digitChars = EnumerablePerformanceTests.RepeatChars("0123456789", maxItemCount).AsString();

            charTest("always true", c => true,
                     times, maxItemCount, digitChars);
            // 1.28 sec.

            charTest("char.IsDigit", c => char.IsDigit(c),
                     times, maxItemCount, digitChars);
            // 1.38 sec.

            charClassPatternTest(new CharGroupPattern(true, "0123456789"),
                                 times, maxItemCount, digitChars);
            // 2.39 sec.

            charClassPatternTest(new CharGroupPattern(true, new[] { new CharRangePattern('0', '9') }),
                                 times, maxItemCount, digitChars);
            // 1.59 sec.

            charClassPatternTest(parseCharClass(@"\d"),
                                 times, maxItemCount, digitChars);
            // 1.80 sec.

            charClassPatternTest(parseCharClass(@"[\d]"),
                                 times, maxItemCount, digitChars);
            // 2.19 sec.


            string lowercaseChars = EnumerablePerformanceTests.RepeatChars("abcdefghijklmnopqrstuvwxyz", maxItemCount).AsString();

            charTest("char.IsLetter", c => char.IsLetter(c),
                     times, maxItemCount, lowercaseChars);
            // 1.42 sec.

            charClassPatternTest(new CharGroupPattern(true, "abcdefghijklmnopqrstuvwxyz"),
                                 times, maxItemCount, lowercaseChars);
            // 2.55 sec.

            charClassPatternTest(new CharGroupPattern(true, new[] { new CharRangePattern('a', 'z') }),
                                 times, maxItemCount, lowercaseChars);
            // 1.65 sec.

            charClassPatternTest(parseCharClass(@"\w"),
                                 times, maxItemCount, digitChars);
            // 2.06 sec.

            charClassPatternTest(parseCharClass(@"[\w]"),
                                 times, maxItemCount, digitChars);
            // 2.42 sec.

            charClassPatternTest(parseCharClass(@"[\s\x00-\x1F\d\w]"),
                                 times, maxItemCount, digitChars);
            // 3.05 sec.


            charTest("char.IsLetterOrDigit", c => char.IsLetterOrDigit(c),
                     times, maxItemCount, lowercaseChars);
            // 1.64 sec.

            charClassPatternTest(new CharGroupPattern(true, "0123456789abcdefghijklmnopqrstuvwxyz"),
                                 times, maxItemCount, lowercaseChars);
            // 2.80 sec.

            charClassPatternTest(new CharGroupPattern(true, new[] { new CharRangePattern('0', '9'),
                                                                    new CharRangePattern('a', 'z') }),
                                 times, maxItemCount, lowercaseChars);
            // 1.69 sec.

            charClassPatternTest(parseCharClass(@"\w"),
                                 times, maxItemCount, digitChars);
            // 2.02 sec.

            charClassPatternTest(parseCharClass(@"[\w-[A-Z]]"),
                                 times, maxItemCount, digitChars);
            // 3.42 sec.


            string repeatedChar = EnumerablePerformanceTests.RepeatChars("7", maxItemCount).AsString();

            charClassPatternTest(new CharGroupPattern(true, "7"),
                                 times, maxItemCount, repeatedChar);
            // 1.97 sec.

            charClassPatternTest(new CharGroupPattern(true, new[] { new CharRangePattern('7', '7') }),
                                 times, maxItemCount, repeatedChar);
            // 1.61 sec.


            // Negative character classes
            charClassPatternTest(new CharGroupPattern(false, "abcdefghijklmnopqrstuvwxyz"),
                                 times, maxItemCount, digitChars);
            // 2.84 sec.

            charClassPatternTest(new CharGroupPattern(false, new[] { new CharRangePattern('a', 'z') }),
                                 times, maxItemCount, digitChars);
            // 1.64 sec.

            charClassPatternTest(parseCharClass(@"[^a-z]"),
                                 times, maxItemCount, digitChars);
            // 2.09 sec.
        }
 public static void CharParserTest <TTree>(Parser <char, TTree> parser, int times, int maxItemCount)
 {
     CharParserTest(parser, times, maxItemCount,
                    EnumerablePerformanceTests.RepeatDigitChars(maxItemCount).AsString());
 }