有人可以解释为什么这些方法之间存在大约 20 倍的巨大差异!?
我的逻辑可以接受 2 次和 4 次之间的差异,但我不明白为什么会发生 20 次。
代码 :
//Method 1 which took 00:00:00.82
DateTime at = DateTime.Now;
for (int i = 0; i < 1000; i++ ) {
var x = (from m in brd.MohreHa select new { m, am = m.GetPossibleMoves().Count() }).OrderByDescending(o => o.am).First().m;
}
var att = DateTime.Now - at;
//Method 2 which took 00:00:15.31
DateTime bt = DateTime.Now;
for (int i = 0; i < 1000; i++) {
var y = brd.MohreHa.First(m => m.GetPossibleMoves().Count() == brd.MohreHa.Max(a => a.GetPossibleMoves().Count()));
}
var btt = DateTime.Now - bt;