static void Main(string[] args)
{
const int COUNT = 1000000;
HashSet<int> hashSetOfInts = new HashSet<int>();
Stopwatch stopWatch = new Stopwatch();
for (int i = 0; i < COUNT; i++)
{
hashSetOfInts.Add(i);
}
stopWatch.Start();
for (int i = 0; i < COUNT; i++)
{
hashSetOfInts.Contains(i);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
stopWatch.Reset();
Dictionary<string, string> domainMap = new Dictionary<string, string>();
for (int i = 0; i < COUNT; i++)
{
domainMap.Add(i.ToString(), i.ToString());
}
stopWatch.Start();
string value;
for (int i = 0; i < COUNT; i++)
{
domainMap.TryGetValue(i.ToString(), out value);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
stopWatch.Reset();
Console.ReadLine();
List<int> listOfInts = new List<int>();
for (int i = 0; i < COUNT; i++)
{
listOfInts.Add(i);
}
stopWatch.Start();
for (int i = 0; i < COUNT; i++)
{
listOfInts.Contains(i);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
Console.WriteLine("结束----");
Console.Read();
}
{
const int COUNT = 1000000;
HashSet<int> hashSetOfInts = new HashSet<int>();
Stopwatch stopWatch = new Stopwatch();
for (int i = 0; i < COUNT; i++)
{
hashSetOfInts.Add(i);
}
stopWatch.Start();
for (int i = 0; i < COUNT; i++)
{
hashSetOfInts.Contains(i);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
stopWatch.Reset();
Dictionary<string, string> domainMap = new Dictionary<string, string>();
for (int i = 0; i < COUNT; i++)
{
domainMap.Add(i.ToString(), i.ToString());
}
stopWatch.Start();
string value;
for (int i = 0; i < COUNT; i++)
{
domainMap.TryGetValue(i.ToString(), out value);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
stopWatch.Reset();
Console.ReadLine();
List<int> listOfInts = new List<int>();
for (int i = 0; i < COUNT; i++)
{
listOfInts.Add(i);
}
stopWatch.Start();
for (int i = 0; i < COUNT; i++)
{
listOfInts.Contains(i);
}
stopWatch.Stop();
Console.WriteLine(stopWatch.Elapsed);
Console.WriteLine("结束----");
Console.Read();
}