Having a big dictionary, say 1M of <double,double> samples – what is the fastest way to iterate over it?
Comparing 3 options (iterate over KeyValuePair in the dictionary, iterate over Values collection and iterate over Keys collection) – below is code and timing comparison results.
// Of course if you iterating over Keys collection and accessing the value by key – it would be the slowest case.
Here are results:
|Method||Time spent in iteration|
|Over key-value pairs||00:00:00.1854684|
|Over Values collection||00:00:00.1221380|
|Over Keys collection||00:00:00.0955291|
Related article: http://dotnetperls.com/dictionary-lookup