I have a very simple SortedSet with a CompareTo method that sorts on the basis of two class fields. As it is used, this collection can get quite big (million+ objects) and grows and grows over time. I have been using a simple Contains method to determine if a new value already exists in the collection...
As an academic exercise I am doing some benchmarks using Linq (which I am fairly new to) to achieve the same effect and am certain that there is some understanding of Linq that I am lacking because I cannot come remotely close to the same performance and I was wondering if some Linq guru could give me a pointer on what could be done to speed it up.
So... The object has a CompareTo that looks something like this:
public int CompareTo(EntityHistoryChange other)
{
int recordIdComp = Recordid.CompareTo(other.Recordid);
int tableIdComp = Tablename.CompareTo(other.Tablename);
if (recordIdComp == 0 && tableIdComp == 0)
return 0;
else if (recordIdComp != 0)
return recordIdComp;
else
return tableIdComp;
}
The corresponding Linq query on simple List:
var handledChange = from thisChange in handledChanges
where thisChange.Recordid == recordId
&& thisChange.Tablename == tableName
select thisChange;
I suppose the results should not surprise me...
Linq Lookup on 18772 rows: 46 ms
SortSet Lookup on 18772 rows: 3 ms
So the question is - what is the equivalent LINQ mechanism?