Calculate the execution time of a method

后端 未结 7 794
小蘑菇
小蘑菇 2020-11-22 13:26

Possible Duplicate:
How do I measure how long a function is running?

I have an I/O time-taking method which c

7条回答
  •  盖世英雄少女心
    2020-11-22 14:17

    StopWatch class looks for your best solution.

    Stopwatch sw = Stopwatch.StartNew();
    DoSomeWork();
    sw.Stop();
    
    Console.WriteLine("Time taken: {0}ms", sw.Elapsed.TotalMilliseconds);
    

    Also it has a static field called Stopwatch.IsHighResolution. Of course, this is a hardware and operating system issue.

    Indicates whether the timer is based on a high-resolution performance counter.

提交回复
热议问题