直接代码:
第一种方法利用System.DateTime.Now
1 public static void SubTest()
2 {
3 DateTime beforeDT = System.DateTime.Now;
4 int[] a = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
5 //Shuffle(a) is the function you want to test.
6 Shuffle(a);
7 DateTime afterDT = System.DateTime.Now;
8 TimeSpan ts = afterDT.Subtract(beforeDT);
9 Console.WriteLine("DateTime costed for Shuffle function is: {0}ms",ts.TotalMilliseconds);
10 }
知识兔第二种用Stopwatch类(System.Diagnostics)
1 public static void SubTest()
2 {
3 Stopwatch sw = new Stopwatch();
4 sw.Start();
5 //Shuffle(a) is the function you want to test.
6 int[] a = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
7 Shuffle(a);
8 sw.Stop();
9 TimeSpan ts = sw.Elapsed;
10 Console.WriteLine("DateTime costed for Shuffle function is: {0}ms", ts.TotalMilliseconds);
11 }
知识兔