监测程序运行的时间,stopWatch

 1    ArrayList arrInt = new ArrayList();
 2                 //用stopwatch来计时 运行的时间
 3             Stopwatch watch = new Stopwatch();
 4             watch.Start();
 5             for (int i = 0; i < 1000000; i++)
 6             {
 7                 arrInt.Add(i);
 8             }
 9             watch.Stop();
10             Console.WriteLine(watch.Elapsed);
11             Console.ReadKey();
12 
13 
14            // 使用泛型集合避免装箱和拆箱。
15             List<int> arrInt1 = new List<int>();
16             Stopwatch watch2 = new Stopwatch();
17             watch2.Start();
18             for (int i = 0; i < 1000000; i++)
19             {
20                 arrInt1.Add(i);
21             }
22             watch2.Stop();
23             Console.WriteLine(watch.Elapsed);
24             Console.ReadKey();

 

posted @ 2016-01-15 17:31  南潇湘  阅读(316)  评论(0编辑  收藏  举报