/// <summary> /// 性能测试 /// </summary> /// <returns></returns> public static void UnitTest_Performance() { Console.WriteLine("UnitTest_Performance"); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int cnt = 0; for (int i = 0; i < 500000; i++) { cnt += i; } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); sw.Reset(); sw.Start(); cnt = foo(); sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); sw.Reset(); sw.Start(); cnt = 0; for (int i = 0; i < 1000000; i++) { FuncCallResult(ref cnt, i); } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); PerfTest test = new PerfTest(); sw.Reset(); sw.Start(); cnt = 0; for (int i = 0; i < 1000000; i++) { test.FuncCallResult(ref cnt, i); } sw.Stop(); Console.WriteLine(string.Format("Elapsed time:{0:0}ms, result = {1}", sw.ElapsedMilliseconds, cnt)); }