Very often use LINQ to filter object array
I ran a test expression that produces the same result, but as different times, I would like to know the reason for this behavior.
public long testTimeOperetionWHERE()
{
Object[] list = opCoIn.getList();
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
int i = 0;
while (i<20000)
{
var result = list.Where(o => o.Id>0)
.Where(o => o.Import>0)
.Where(o => o.OrderConfirm==o.NumberConfirm)
.Where(o => o.IdActiveCustomer>100 );
i++;
}
long e = sw.ElapsedMilliseconds;
return e;
}
The time cost result always varies between 90-80
In this case
public long testTimeOperetionAND()
{
Object[] list = opCoIn.getList();
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
int i = 0;
while (i < 20000)
{
var result = list.Where(o => o.Id > 0
&& o.Import > 0
&& o.OrderConfirm==o.NumberConfirm
&& o.IdActiveCustomer>100);
i++;
}
long e = sw.ElapsedMilliseconds;
return e;
}
The time cost is always less than 5