using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace hashVsDictionary
{
internal class Program
{
private static void Main(string[] args)
{
#region init
int num = 10000000;
Guid[] guids = new Guid[num];
Stopwatch s = new Stopwatch();
s.Start();
for (int i = 0; i < num; i++)
{
guids[i] = Guid.NewGuid();
}
s.Stop();
Console.WriteLine("Data Creation = " + s.Elapsed);
s.Reset();
#endregion
#region hash
Hashtable hash = new Hashtable();
s.Start();
for (int i = 0; i < num; i++)
{
hash.Add(guids[i], true);
}
s.Stop();
Console.WriteLine("Insert Hash = " + s.Elapsed);
s.Reset();
s.Start();
for (int i = 0; i < num; i++)
{
bool b = Convert.ToBoolean(hash[guids[i]]);
}
Console.WriteLine("Extracting Hash = " + s.Elapsed);
s.Reset();
s.Start();
for (int i = 0; i < num; i++)
{
hash.Remove(guids[i]);
}
Console.WriteLine("Removing Hash = " + s.Elapsed);
s.Reset();
#endregion
#region dict
Dictionary<Guid, bool> dict = new Dictionary<Guid, bool>();
s.Start();
for (int i = 0; i < num; i++)
{
dict.Add(guids[i], true);
}
s.Stop();
Console.WriteLine("Insert Dictionary = " + s.Elapsed);
s.Reset();
s.Start();
for (int i = 0; i < num; i++)
{
bool b = dict[guids[i]];
}
Console.WriteLine("Extracting Dict = " + s.Elapsed);
s.Reset();
s.Start();
for (int i = 0; i < num; i++)
{
dict.Remove(guids[i]);
}
Console.WriteLine("Removing Dict = " + s.Elapsed);
s.Reset();
#endregion
Console.ReadLine();
}
}
}