using System.Diagnostics; Stopwatch sw = new Stopwatch(); sw.Start(); //todo code ....... sw.Stop(); Console.WriteLine("执行此段代码耗时:{0} ms", sw.ElapsedMilliseconds);