Skip to content

Instantly share code, notes, and snippets.

@adriang133
Created February 3, 2016 08:47
Show Gist options
  • Save adriang133/16da77ca307049ddca49 to your computer and use it in GitHub Desktop.
Save adriang133/16da77ca307049ddca49 to your computer and use it in GitHub Desktop.
Performance test
LogicalExpression testCustomExp = CustomLogicalExpressionHelper.ParseXml(testP);
Expression exp = LogicalExpressionHelper.ParseXml(testP);
var expParams = LogicalExpressionHelper.GetParameters(exp);
LambdaExpression lambda = Expression.Lambda(exp, expParams.Keys);
Delegate d = lambda.Compile();
string[] parameters = new string[] {"a", "b", "d", "e" };
int numberOfTests = 100000;
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 1; i <= numberOfTests; i++ )
{
bool tr = (bool)d.DynamicInvoke(expParams.Values.Cast<object>().ToArray());
}
sw.Stop();
Console.WriteLine("Standard: " + sw.ElapsedMilliseconds);
sw.Restart();
for (int i = 1; i <= numberOfTests; i++)
{
bool tr = testCustomExp.Evaluate(parameters);
}
sw.Stop();
Console.WriteLine("Custom: " + sw.ElapsedMilliseconds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment