static void SubTest() { DateTime beforDT = System.DateTime.Now; //耗時巨大的代碼 DateTime afterDT = System.DateTime.Now; TimeSpan ts = afterDT.Subtract(beforDT); Console.WriteLine("DateTime總共花費{0}ms.", ts.TotalMilliseconds); } static void SubTest() { Stopwatch sw = new Stopwatch(); sw.Start(); //耗時巨大的代碼 sw.Stop(); TimeSpan ts2 = sw.Elapsed; Console.WriteLine("Stopwatch總共花費{0}ms.", ts2.TotalMilliseconds); }
