您的位置:首页 > 编程语言 > C#

C#:程序控制--计算程序执行耗费的时间

2016-10-01 14:21 281 查看
计算程序执行耗费的时间

代码:

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

namespace watch
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine("开始计时");
sw.Start();

int s = 0;
for (int i = 0; i < 10000000; i++)
{
s += i;
}
sw.Stop();
Console.WriteLine("执行完毕,停止计时.程序执行耗时{0}毫秒", sw.ElapsedMilliseconds);
}
}
}


实验结果截图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: