基准比较两个表达式评估器的方法?

时间:2015-10-05 06:44:05

标签: c# performance expression performance-testing query-performance

我目前要求将两个表达式赋值器与1000行数据上的一个表达式进行比较,以记录处理时间。

我的表达是:

if ( val1 > 0 ) 
then (
       ( val2 / val3 ) >= 34 and ( val4 / val5 ) <= 4500
     ) 
else ( 
      if ( val1 equals 0) 
      then true 
      else false
    )   

我将使用1000个不同的val1,val2,val3,val4和val5变量值,并尝试在循环中迭代它。我需要记录处理结果,即在单个表达式上评估1000条记录需要多少秒。

我将要使用的表达式评估者是:NCalc [https://ncalc.codeplex.com/]和Expression Evaluator [https://csharpeval.codeplex.com/]。 请建议我在C#中记录基准测试结果的方法。可以使用C#中的简单控制台应用程序来完成,还是可以使用任何第三方工具?

1 个答案:

答案 0 :(得分:2)

您可以使用Stopwatch

使用简单的计时器
var timer = new Stopwatch();
timer.Start();

// Do your stuff

timer.Stop();

Console.WriteLine("This operation took " + timer.ElapsedMilliseconds + " ms.");
相关问题