Home  >  Article  >  Backend Development  >  C# method to test code execution time

C# method to test code execution time

大家讲道理
大家讲道理Original
2016-11-11 14:48:321368browse

Stopwatch sw = new Stopwatch();  
sw.Start();  
//这里填写要执行的代码  
sw.Stop();  
Console.WriteLine("总运行时间:" + sw.Elapsed);  
Console.WriteLine("测量实例得出的总运行时间(毫秒为单位):" + sw.ElapsedMilliseconds);  
Console.WriteLine("总运行时间(计时器刻度标识):" + sw.ElapsedTicks);  
Console.WriteLine("计时器是否运行:" + sw.IsRunning.ToString());

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn