It works for me in 0.34 seconds down from 9+ minutes
The problem is comparing KeyValuePair structures. I worked on it by writing a comparator object and passed its instance to the dictionary.
From what I can determine, KeyValuePair.GetHashCode () returns the hash code of this Key object (in this example, the least unique object).
As the dictionary adds (and checks for the existence) of each element, it uses the Equals and GetHashCode functions, but must rely on the Equals function when the hash code is less unique.
Providing the more unique GetHashCode function, it performs the Equals function much less frequently. I also optimized the Equals function to compare more unique values โโbefore less significant keys.
86,000 * 11 objects with 10,000 unique properties work after 0.34 seconds using the comparison object below (without the comparison object, it takes 9 minutes 22 seconds)
Hope this helps :)
class StringPairComparer : IEqualityComparer<KeyValuePair<string, string>> { public bool Equals(KeyValuePair<string, string> x, KeyValuePair<string, string> y) { return x.Value == y.Value && x.Key == y.Key; } public int GetHashCode(KeyValuePair<string, string> obj) { return (obj.Key + obj.Value).GetHashCode(); } }
EDIT : if it was only one line (instead of KeyValuePair, where string = Name + Value), it will be about twice as fast. This is a good interesting problem, and I spent too much time on it (I learned a little quietly)
Binary binary
source share