1 static void Main(string[] args)
2 {
3long _start,_end,_loops; //DateTime.Now.Ticks是long int
4 _loops=100000; //重复次数
5 _start=DateTime.Now.Ticks;
6
7 for (int i=0;i<_loops;i++)
8 {
9 原方法;
10 }
11 _end=DateTime.Now.Ticks;
12
13 Console.WriteLine("{0}次调用原方法共花费时间{1}ms",_loops,(_end-_start)/10000);
14
15 _start=DateTime.Now.Ticks;
16
17 for (int i=0;i<_loops;i++)
18 {
19 优化后方法;
20 }
21 _end=DateTime.Now.Ticks;
22
23 Console.WriteLine("{0}次调用优化后方法共花费时间{1}ms",_loops,(_end-_start)/10000);
24 }
转自: