Calculate the execution time of a method

后端 未结 7 876
小蘑菇
小蘑菇 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:04

     using System.Diagnostics;
     class Program
     {
        static void Test1()
        {
            for (int i = 1; i <= 100; i++)
            {
                Console.WriteLine("Test1 " + i);
            }
        }
      static void Main(string[] args)
        {
    
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Test1();
            sw.Stop();
            Console.WriteLine("Time Taken-->{0}",sw.ElapsedMilliseconds);
       }
     }
    

提交回复
热议问题