C#测程序运行时间

System.Diagnostics.Stopwatch Runtime = new System.Diagnostics.Stopwatch();
        public Form1()
        {
            InitializeComponent();
        }

 private void button1_Click(object sender, EventArgs e)
        {
            Runtime.Restart();
            int rr = 100;
            int bb = 800;
            int sum = 0;
            for (int i = 0; i < rr; i++)
            {
                for (int j = 0; j < bb; j++)
                {
                    if (i==j)
                    {
                        sum += (i + j);
                    }               
                }
            }

            Runtime.Stop();
            TimeSpan timespan = Runtime.Elapsed;
           
Console.WriteLine(timespan);
        }

猜你喜欢

转载自blog.csdn.net/qq_40433102/article/details/85157777