本文共 1507 字,大约阅读时间需要 5 分钟。
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;namespace UrlMatchSiteNameModule{ class Program { static void Main(string[] args) { const int COUNT = 1000000; HashSet hashSetOfInts = new HashSet (); 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(); DictionarydomainMap = new Dictionary (); 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(); List listOfInts = new List (); 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.Read(); } }}
转载地址:http://rrunb.baihongyu.com/