| 三、HashSet (100W,100W) Stopwatch timer = new Stopwatch(); timer.Start(); System.Collections.Generic.HashSet for (int i = 0; i < 1000000; i++) { ht.Add(i); } timer.Stop(); Console.Write(timer.ElapsedMilliseconds.ToString() + "\t"); Stopwatch timer1 = new Stopwatch(); timer1.Start(); for (int i = 0; i < 1000000; i++) { ht.Contains(i); } timer1.Stop(); Console.WriteLine(timer1.ElapsedMilliseconds.ToString()); 89 32 79 32 79 32 117 31 |
| 四、List (100W,1W) Stopwatch timer = new Stopwatch(); timer.Start(); System.Collections.Generic.List for (int i = 0; i < 1000000; i++) { ht.Add(i); } timer.Stop(); Console.Write(timer.ElapsedMilliseconds.ToString() + "\t"); Stopwatch timer1 = new Stopwatch(); timer1.Start(); for (int i = 0; i < 10000; i++) { ht.Contains(i); } timer1.Stop(); Console.WriteLine(timer1.ElapsedMilliseconds.ToString()); 16 379 19 392 18 403 18 392 |
把List换成List

