Benchmarking experiment 1

How much time does it take to check whether an element is present in a list-based collection?

In order to determine whether a given item is in a collection or not, we have to call the Contains() method on linear containers.

The following are the steps to create the benchmarking code that I have used. You shall have to change the Contain() method accordingly, to alter it for the next benchmarking on another equivalent container:

  1. Create a console app.
  2. In the Main() method, add the following code:
    static void Main(string[] args)
    {
      HashSet<char> codes = new HashSet<char>();
      string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      foreach (char c in alphabets)
      codes.Add(c); 
     Dictionary<int, double> perfMap = new Dictionary<int, ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.