I'm coding an computationally expensive application (NLP machine learning task) which is in a need of optimization.
Since my code has a lot of for-loops, I've used the Parallel.For
(and variants) to parallelize the outer-most loops.
I've also used arrays and Dictionary
s to build a few indices which cut the cost considerably.
VS2010's profiler indicated that the application spends most of it's time in Dictionary.TryGetValue()
(which is a side-product of indices).
This begs the question whether I can do better? And how?
My first question is whether there is general consensus that ConcurrentDictionary.TryGetValue
performs any better than
Dictionary.TryGetValue
in my scenario -- many readers, no writers?
I'm not motivated to code my own hashmap as it will probably fare worse than .NET's collections. But are there any libraries out there that guarantee faster lookups for my scenario?
Perhaps the hashcode implementation is slowing things down?