I do a search Dictionary<>in O (n ^ 2) loop and need it to be ridiculously fast. Not this. Does anyone know how to implement Dictionary<>? I test the performance of a dictionary with an isolated test case after running my code through the profiler, and determining the search in the Dictionary is the main part of the processor time. My test code is as follows:
Int32[] keys = new Int32[10] { 38784, 19294, 109574, 2450985, 5, 398, 98405, 12093, 909802, 38294394 };
Dictionary<Int32, MyData> map = new Dictionary<Int32, MyData>();
//Add a bunch of things to map
timer.Start();
Object item;
for (int i = 0; i < 1000000; i++)
{
for (int j = 0; j < keys.Length; j++)
{
bool isFound = map.ContainsKey(keys[j]);
if (isFound)
{
item = map[keys[j]];
}
}
}
timer.Stop();
ContainsKey and map [] are two slow parts (equally slow). If I add TryGetValue, it is almost identical in speed to ContainsKey. Here are some interesting facts.
A Dictionary<Guid, T> , Dictionary<Int32, T>. Dictionary<String, T> , Guid. A Dictionary<Byte, T> 50% , Ints. , O (log n), , . - , Hashtable, .NET Hashtable, , .
, , , . . , , 10 , 2 000 . - - , ? !
Mike