using System.Text.RegularExpressions;
public static void Main()
string eqOutput = "(1||0)&&(!1)";
var watch = System.Diagnostics.Stopwatch.StartNew();
var notMatcher = new Regex(@"![01]", RegexOptions.Compiled);
var andMatcher = new Regex(@"[01]&&[01]", RegexOptions.Compiled);
var orMatcher = new Regex(@"[01]\|\|[01]", RegexOptions.Compiled);
var parenMatcher = new Regex(@"\([01]\)", RegexOptions.Compiled);
for (int x = 0; x < 10000; x++)
while (eqOutput.Length > 1)
while (notMatcher.IsMatch(eqOutput))
while (andMatcher.IsMatch(eqOutput))
while (orMatcher.IsMatch(eqOutput))
while (parenMatcher.IsMatch(eqOutput))
long timeForFirst = watch.ElapsedMilliseconds;
for (int x = 0; x < 10000; x++)
while (eqOutput.Length > 1)
if (eqOutput.Contains("!1"))
eqOutput = eqOutput.Replace("!1", "0");
else if (eqOutput.Contains("!0"))
eqOutput = eqOutput.Replace("!0", "1");
else if (eqOutput.Contains("1&&1"))
eqOutput = eqOutput.Replace("1&&1", "1");
else if (eqOutput.Contains("1&&0"))
eqOutput = eqOutput.Replace("1&&0", "0");
else if (eqOutput.Contains("0&&1"))
eqOutput = eqOutput.Replace("0&&1", "0");
else if (eqOutput.Contains("0&&0"))
eqOutput = eqOutput.Replace("0&&0", "0");
else if (eqOutput.Contains("1||1"))
eqOutput = eqOutput.Replace("1||1", "1");
else if (eqOutput.Contains("1||0"))
eqOutput = eqOutput.Replace("1||0", "1");
else if (eqOutput.Contains("0||1"))
eqOutput = eqOutput.Replace("0||1", "1");
else if (eqOutput.Contains("0||0"))
eqOutput = eqOutput.Replace("0||0", "0");
else if (eqOutput.Contains("(1)"))
eqOutput = eqOutput.Replace("(1)", "1");
else if (eqOutput.Contains("(0)"))
eqOutput = eqOutput.Replace("(0)", "0");
long timeForSecond = watch.ElapsedMilliseconds;
Console.WriteLine("First: " + timeForFirst.ToString());
Console.WriteLine("Second: " + timeForSecond.ToString());