C#之使用Stopwatch监视运行时间

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace 使用Stopwatch01
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
//System.Diagnostics.Stopwatch 可以用来测量程序段的运行时间
            
//一般情况下在有多种途径(算法)来实现同一功能时,我们可能想对这两种方法进行一个比较,这个时候简单的使用下Stopwatch就可以有个大致的概念.
            int i = 0;
            
int sum = 0;
            Stopwatch sw 
= new Stopwatch();
            sw.Start();
            
for (i = 0; i < 10000;i++ )
            {
                sum
+=i;               
                Console.WriteLine(sum);
            }
            sw.Stop();
            Console.WriteLine(
"使用时间" + sw.ElapsedMilliseconds);
            Console.ReadKey();
        }
    }
}
原文地址:https://www.cnblogs.com/lizunicon/p/1394507.html