|
Functionality implemented by the MultiKeyDictionary<TKey1, TKey2, TValue>
class is similar to functionality of the Dictionary<Tuple<TKey1, TKey2>, TValue>
class.
But MultiKeyDictionary class is much faster.
To check the speed of MultiKeyDictionary class add two files contained
in the TupleDictionaryTest subdirectory to the new ConsoleApplication,
then run the application to get actual to your computer results.
On my Intel Core i5 (2.67 GHz, 8 Gb RAM) computer under Windows 7 64bit TupleDictionaryTest
application produces the following results:
MultiKeyDictionary
TupleDictionary
<int, int, int>
Add:
101 ms 1994 ms
TryGetValue: 39 ms
1841 ms
2 * TryGetValue: 98 ms
5505 ms
Remove: 14
ms 510 ms
Clear: 0 ms 3
ms
<string, string, int>
Add:
592 ms 751 ms
TryGetValue: 285 ms
623 ms
2 * TryGetValue: 907 ms
1706 ms
Remove: 71
ms 189 ms
Clear:
0 ms 3
ms
So MultiKeyDictionary<int, int, int> class performs about 20-50 times
faster than Dictionary<Tuple<int, int>, int>
class.
Whereas MultiKeyDictionary<string, string, int> class performs
only about 2 times faster than Dictionary<Tuple<string, string>,
int>
class.
IMHO the difference between the two results is explained by string interning.
You can play with this test application to check performance of
other MultiKeyDictionary class kinds and other MultiKeyDictionary's
generic type arguments. |