このコードの実行速度は非常に遅いです:
public static class DB
{
readonly static InlineSql sql = new InlineSql();
public static IEnumerable<LabItem> GetLabItemsFromLabLineItems(IEnumerable<LabLineItem> items)
{
/*
* Business Rule :
* The sproc used to retrieve lab line items has no way of "grouping" lab items out of line items.
* To compensate, the sproc orders its results by IDCode, we group everything and use the first of each grouping to represent that ID Code.
* That very same item is also the first item in its Items property.
* */
return items
.GroupBy(c => c.IDCode , c => c, (c, d) => d.First())
.Select(c => new LabItem(c.IDCode, c.OrderGuid, c.Name, c.SignificantDtm, c.Status, c.Description, items.Where(d => string.Compare(d.IDCode, c.IDCode, true) == 0 )));
}
}
特に、d.IDCode を c.IDCode と比較する select ステートメントが問題のようです。この行は、14.8 の %Time で ANTS から 9000 万のヒット数を報告しています。 items.count
約9千です。
ブレークポイントが 9000 万回ヒットしていないことはわかっています。ここでヒット数とはどういう意味ですか?
その他の便利なコード:
LabItem
List<LabLineItem>
ここで比較するもの があります。LabLineItem.Equals
:
public override bool Equals(object obj)
{
LabLineItem otherItem = obj as LabLineItem;
if (otherItem == null) return false;
return
OrderGuid == otherItem.OrderGuid
&& IDCode == otherItem.IDCode
&& SignificantDtm == otherItem.SignificantDtm
&& ObservationGuid == otherItem.ObservationGuid
&& string.Compare(Value, otherItem.Value, true) == 0;
}
public override int GetHashCode()
{
return
OrderGuid.GetHashCode()
^ IDCode.GetHashCode()
^ SignificantDtm.GetHashCode()
^ ObservationGuid.GetHashCode();
}