I have the following code:
// Dictionary which I want to optimize
Dictionary<string, MyClass> myDict;
//
Dictionary<int, KKSKey> kksKeyList;
...
...
...
// Classes
[Serializable]
public class MyClass : MyBaseClass
{
Dictionary<int, DebugValue> myDebugValues;
...
...
...
}
//
[Serializable]
public class DebugValue
{
public int ValueType {get;set;}
public double Value {get;set;}
...
...
...
}
public class KKSKey
{
public string KKS { set; get; }
public string Variable { set; get; }
...
...
...
}
The reason I used dictionaries everywhere is because I need to access the lists by a key.
I have the following lines in a for loop that runs just over 550,000 (yes!) times. myDict has about 10,000 items and kksKeyList has over 550,000 items.
Each of the following lines runs for i = 0 to 550,000:
myDict[kksKeyList[i].KKS].myDebugValues[i].ValueType = DOUBLE;
myDict[kksKeyList[i].KKS].myDebugValues[i].Value = tempdouble;
Basically, the above lines are filling up the dictionary items with raw data received over TCP. Each one of the above line takes about 90-100 milliseconds per for loop (550,000 times). This is not acceptable for my application. It must complete one of above lines within 50 milliseconds. Can anyone suggest how to optimize the performance of above operation? I am open to any suggestions, even if it means redefining the related classes if necessary.
You can try:
or maybe:
If it suits your constructor…