Using ConcurrentDictionary
This recipe shows you a very simple scenario, comparing the performance of a usual dictionary collection with the concurrent dictionary in a single-threaded environment.
Getting ready
To work through this recipe, you will need Visual Studio 2015. There are no other prerequisites. The source code for this recipe can be found at BookSamples\Chapter6\Recipe1
.
How to do it...
To understand the difference between the performance of a usual dictionary collection and the concurrent dictionary, perform the following steps:
Start Visual Studio 2015. Create a new C# console application project.
In the
Program.cs
file, add the followingusing
directives:using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using static System.Console;
Add the following code snippet below the
Main
method:const string Item = "Dictionary item"; const int Iterations = 1000000; public static string CurrentItem;
Add the following code snippet inside the
Main
method...