static void Main(string[] args) { List<int> list = new List<int>(); for (int i = 0; i < 100; i++) { list.Add(i); } Stopwatch watch = new Stopwatch(); watch.Start(); int ret=0; for (int i = 0; i < 1000000; i++) { ret = list.BinarySearch(13); if (ret >= 0) ret = list[ret]; } watch.Stop(); Console.WriteLine("BinarySearch watch=" + watch.ElapsedMilliseconds+" ret="+ret); Stopwatch watch2 = new Stopwatch(); watch2.Start(); int ret2=0; for (int i = 0; i < 1000000; i++) { ret2= list.Find(a => a == 13); } watch2.Stop(); Console.WriteLine("Find watch=" + watch2.ElapsedMilliseconds + " ret2=" + ret2); }
转载于:https://www.cnblogs.com/doujiaomifan/p/3519208.html