var sw = new System.Diagnostics.Stopwatch(); sw.Start(); 我是中间要执行测试的代码 sw.Stop(); var ts = sw.Elapsed; System.Diagnostics.Debug.WriteLine("代码总用时:{0}", ts.TotalMilliseconds);