Stopwatch sw = new Stopwatch(); sw.Start();//开始计时 //---------------------------------------------------------------- //需要计时的运行代码 //---------------------------------------------------------------- sw.Stop();//结束时间 Console.WriteLine(sw.ElapsedMilliseconds);//输出计时