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("##############################################################"); } }
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("##############################################################"); } }
public void ReplaceTest5() { var oregex = new DebugORegex("{a}*"); var input = @"11".ToCharArray(); var replace = new string(oregex.Replace(input, x => new[] { '2', '3', '4', '5' })); Assert.AreEqual("23451234512345",replace); Console.WriteLine(replace); }
public void ReplaceTest3() { var oregex = new DebugORegex("{a}+"); var input = @"1aaa1aaa1aaa111111a1a1".ToCharArray(); var replace = new string(oregex.Replace(input, x => new []{'2','3','4'})); Assert.AreEqual("12341234123411111123412341",replace); Console.WriteLine(replace); }
public void ReplaceTest2() { var oregex = new DebugORegex("{a}+"); var input = @"1aaa1aaa1aaa111111a1a1".ToCharArray(); var replace = new string(oregex.Replace(input, x => new char[0])); Assert.AreEqual("11111111111",replace); Console.WriteLine(replace); }
public void ReplaceTest5() { var oregex = new DebugORegex("{a}*"); var input = @"11".ToCharArray(); var replace = new string(oregex.Replace(input, x => new[] { '2', '3', '4', '5' })); Assert.AreEqual("23451234512345", replace); Console.WriteLine(replace); }
public void ReplaceTest3() { var oregex = new DebugORegex("{a}+"); var input = @"1aaa1aaa1aaa111111a1a1".ToCharArray(); var replace = new string(oregex.Replace(input, x => new [] { '2', '3', '4' })); Assert.AreEqual("12341234123411111123412341", replace); Console.WriteLine(replace); }
public void ReplaceTest2() { var oregex = new DebugORegex("{a}+"); var input = @"1aaa1aaa1aaa111111a1a1".ToCharArray(); var replace = new string(oregex.Replace(input, x => new char[0])); Assert.AreEqual("11111111111", replace); Console.WriteLine(replace); }
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(); } }
public void BuildTest() { const string pattern = "({x}+{x}+){y}+{x}|{x}|{x}|{x}|{y}|{x}[^{x}][^{y}]?|(?<g1>{x}+?|(?<g2>{x}?)?)"; Console.WriteLine("Input pattern: {0}", pattern); const int iterCount = 10; const int repeatCount = 10; for (int j = 0; j < iterCount; j++) { var sw = Extensions.Measure(() => { for (int i = 0; i < repeatCount; i++) { // ReSharper disable once UnusedVariable var oregex = new DebugORegex(pattern); } }); Console.WriteLine("Done {0} in {1}", repeatCount, sw.Elapsed); } }
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); }
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); }