Exemplo n.º 1
0
        public void LegasyTest(SingleFileTest test)
        {
            var xreg = test.GetRoot().Element(RegexTag);
            var xoreg = test.GetRoot().Element(OregexTag);
            var regexOptions = GetRegexOptions(xreg);
            var oRegexOptions = GetORegexOptions(xoreg);

            // ReSharper disable once PossibleNullReferenceException
            var regexPattern = xreg.Value;
            // ReSharper disable once PossibleNullReferenceException
            var oregexPattern = xoreg.Value;

            // ReSharper disable once PossibleNullReferenceException
            var text = test.GetRoot().Element(TextTag).Value;

            var regex = new Regex(regexPattern, regexOptions);
            var oregex = new DebugORegex(oregexPattern, oRegexOptions);

            var regexMatches = regex.Matches(text).Cast<Match>().ToArray();
            var oregexMatches = oregex.Matches(text.ToCharArray()).ToArray();

            Trace.TraceInformation("Text length: "+ text.Length + "\n");


            Console.WriteLine("##############################################################");
            try
            {
                Assert.AreEqual(regexMatches.Length, oregexMatches.Length);
                for (int i = 0; i < regexMatches.Length; i++)
                {
                    var rm = regexMatches[i];
                    var orm = oregexMatches[i];
                    Compare(rm, orm);
                }
            }
            catch
            {
                Console.WriteLine("##############################################################");
                Console.WriteLine("#                         EXPECTED                           #");
                Console.WriteLine("##############################################################");
                foreach (var m in regexMatches)
                {
                    Console.WriteLine(ExpectedString(m));
                }
                throw;
            }
            finally
            {
                Console.WriteLine("##############################################################");
                Console.WriteLine("#                         ACTUAL                             #");
                Console.WriteLine("##############################################################");
                foreach (var m in oregexMatches)
                {
                    Console.WriteLine(ActualString(m));
                }
                Console.WriteLine("##############################################################");
            }


        }
Exemplo n.º 2
0
        public void LegasyTest(SingleFileTest test)
        {
            var xreg          = test.GetRoot().Element(RegexTag);
            var xoreg         = test.GetRoot().Element(OregexTag);
            var regexOptions  = GetRegexOptions(xreg);
            var oRegexOptions = GetORegexOptions(xoreg);

            // ReSharper disable once PossibleNullReferenceException
            var regexPattern = xreg.Value;
            // ReSharper disable once PossibleNullReferenceException
            var oregexPattern = xoreg.Value;

            // ReSharper disable once PossibleNullReferenceException
            var text = test.GetRoot().Element(TextTag).Value;

            var regex  = new Regex(regexPattern, regexOptions);
            var oregex = new DebugORegex(oregexPattern, oRegexOptions);

            var regexMatches  = regex.Matches(text).Cast <Match>().ToArray();
            var oregexMatches = oregex.Matches(text.ToCharArray()).ToArray();

            Trace.TraceInformation("Text length: " + text.Length + "\n");


            Console.WriteLine("##############################################################");
            try
            {
                Assert.AreEqual(regexMatches.Length, oregexMatches.Length);
                for (int i = 0; i < regexMatches.Length; i++)
                {
                    var rm  = regexMatches[i];
                    var orm = oregexMatches[i];
                    Compare(rm, orm);
                }
            }
            catch
            {
                Console.WriteLine("##############################################################");
                Console.WriteLine("#                         EXPECTED                           #");
                Console.WriteLine("##############################################################");
                foreach (var m in regexMatches)
                {
                    Console.WriteLine(ExpectedString(m));
                }
                throw;
            }
            finally
            {
                Console.WriteLine("##############################################################");
                Console.WriteLine("#                         ACTUAL                             #");
                Console.WriteLine("##############################################################");
                foreach (var m in oregexMatches)
                {
                    Console.WriteLine(ActualString(m));
                }
                Console.WriteLine("##############################################################");
            }
        }
Exemplo n.º 3
0
        public void RunTest(int iterCount)
        {
            var str = SingleFileTestFactory.GetTestData("Performance//random.txt");
            var input = str.ToCharArray();
            var oregex = new DebugORegex("{a}({b}{a})+");

            for (int i = 0; i < iterCount; i++)
            {
                oregex.Matches(input).Evaluate();
            }
        }
Exemplo n.º 4
0
        public void RunTest(int iterCount)
        {
            var str    = SingleFileTestFactory.GetTestData("Performance//random.txt");
            var input  = str.ToCharArray();
            var oregex = new DebugORegex("{a}({b}{a})+");

            for (int i = 0; i < iterCount; i++)
            {
                oregex.Matches(input).Evaluate();
            }
        }
Exemplo n.º 5
0
        private static void PerformanceTest(string oregexPattern, string regexPattern, string inputText, int iterCount,
                                            bool outputTotal = false)
        {
            var input  = inputText.ToCharArray();
            var oregex = new DebugORegex(oregexPattern);
            var regex  = new Regex(regexPattern,
                                   RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.Compiled);

            if (input.Length <= 3000)
            {
                Console.WriteLine("Input string: {0}", inputText);
            }

            var regexCount  = new TimeSpan();
            var oregexCount = new TimeSpan();
            var table       = new DataTable();

            table.Columns.Add("№", typeof(int));
            table.Columns.Add("ORegex", typeof(TimeSpan));
            table.Columns.Add("Regex", typeof(TimeSpan));
            table.Columns.Add("Ratio", typeof(double));

            for (int j = 0; j < iterCount; j++)
            {
                var sw1 = Extensions.Measure(() => oregex.Matches(input));
                oregexCount += sw1.Elapsed;

                var sw2 = Extensions.Measure(() => regex.Matches(inputText).Cast <Match>().Evaluate());
                regexCount += sw2.Elapsed;

                table.Rows.Add(j + 1, sw1.Elapsed, sw2.Elapsed,
                               Math.Round(sw2.ElapsedTicks / (double)sw1.ElapsedTicks, 2));
            }

            if (outputTotal)
            {
                table.Rows.Add(0, oregexCount, regexCount, Math.Round(oregexCount.Ticks / (double)regexCount.Ticks, 3));
            }

            Console.WriteLine("ORegex pattern: {0}; Regex pattern: {1}.", oregexPattern, regexPattern);
            PrintTable(table);
        }
Exemplo n.º 6
0
        private static void PerformanceTest(string oregexPattern, string regexPattern, string inputText, int iterCount,
            bool outputTotal = false)
        {
            var input = inputText.ToCharArray();
            var oregex = new DebugORegex(oregexPattern);
            var regex = new Regex(regexPattern,
                RegexOptions.ExplicitCapture | RegexOptions.Singleline | RegexOptions.Compiled);
            if (input.Length <= 3000)
            {
                Console.WriteLine("Input string: {0}", inputText);
            }

            var regexCount = new TimeSpan();
            var oregexCount = new TimeSpan();
            var table = new DataTable();
            table.Columns.Add("№", typeof (int));
            table.Columns.Add("ORegex", typeof (TimeSpan));
            table.Columns.Add("Regex", typeof (TimeSpan));
            table.Columns.Add("Ratio", typeof (double));

            for (int j = 0; j < iterCount; j++)
            {
                var sw1 = Extensions.Measure(() => oregex.Matches(input));
                oregexCount += sw1.Elapsed;

                var sw2 = Extensions.Measure(() => regex.Matches(inputText).Cast<Match>().Evaluate());
                regexCount += sw2.Elapsed;

                table.Rows.Add(j + 1, sw1.Elapsed, sw2.Elapsed,
                    Math.Round(sw2.ElapsedTicks/(double) sw1.ElapsedTicks, 2));
            }

            if (outputTotal)
            {
                table.Rows.Add(0, oregexCount, regexCount, Math.Round(oregexCount.Ticks/(double) regexCount.Ticks, 3));
            }

            Console.WriteLine("ORegex pattern: {0}; Regex pattern: {1}.", oregexPattern, regexPattern);
            PrintTable(table);
        }