本文共 722 字,大约阅读时间需要 2 分钟。
using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication14{ class Program { [Conditional("DEBUG")] static void Main(string[] args) { Stopwatch timer = new Stopwatch();//new一个stopwatch long total = 0; timer.Start();//开始计算时间 for (long i = 0; i < 1000000000; i++)//10亿 { total += 1; } timer.Stop();//结束点,另外stopwatch还有Reset方法,可以重置。 Console.WriteLine(total); Console.WriteLine(timer.Elapsed);//显示时间 Console.WriteLine(timer.ElapsedMilliseconds);// 显示到毫秒 } }}
转载地址:http://jtdaf.baihongyu.com/