I have a list of audit data from Dynamics CRM 2013 that I deserialised and stuck in a HashSet that is defined as:
private class AuditCache
{
public Guid ObjectId;
public int HistoryId;
public DateTime? DateFrom;
public DateTime? DateTo;
public string Value;
};
private HashSet<AuditCache> _ac = new HashSet<AuditCache>();
I am adding such data (from the SQL Server recordset):
_ac.Add(new AuditCache{
ObjectId = currentObjectId,
HistoryId = Convert.ToInt32(dr["HistoryId"]),
DateTo = Convert.ToDateTime(dr["CreatedOn"]),
Value = value});
As a result, I get about half a million records.
Next, I need to iterate through each Guid and pull a subset of the data from my audit data that matches. I have a list of Guides that I create elsewhere, and their processing is about 300,000. I store them in this:
var workList = new Dictionary<Guid, DateTime>();
... and iterate over them like this:
foreach (var g in workList)
Then I need to do this to pull out a subset for each Guid:
List<AuditCache> currentSet = _ac.Where(v => v.ObjectId == g.Key).ToList();
But he is slow.
1 , ( , 1% ), , .
, , , , Guid. , : / (?) / ?
: , /, - , Dynamics CRM. , "" - , , ?
, , (371 901 Guids), 1000 . , /INSERT SQL Server, .
Method #0 - List with Lambda ~30.00s per 1,000 rows (I never benchmarked this precisely)
Method #1 - IntersectWith 40.24s per 1,000 rows (cloning my Hashset spoilt this)
Method #2 - BinarySearch 3.20s per 1,000 rows
Method #3 - Generic Dictionary 2.19s per 1,000 rows
, , , , , , , .
, . BinarySearch , , , , .
, IntersectWith "" , , .