随笔-34  评论-0  文章-0  trackbacks-1

C#中提供的精准测试程序运行时间的类Stopwatch

在需要对程序的执行时间进行精准测试的程序员,不妨使用.Net提供的Stopwatch类,它的命名空间是:System.Diagnostics
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace StopWatch
{
    
class Program
    {
        
static void Main(string[] args)
        {
            Stopwatch sw 
= new Stopwatch();
            sw.Start();
            
//这里填写要执行的代码
            sw.Stop();
            Console.WriteLine(
"总运行时间:" + sw.Elapsed);
            Console.WriteLine(
"测量实例得出的总运行时间(毫秒为单位):" + sw.ElapsedMilliseconds);
            Console.WriteLine(
"总运行时间(计时器刻度标识):" + sw.ElapsedTicks);
            Console.WriteLine(
"计时器是否运行:" + sw.IsRunning.ToString());
        }
    }
}
posted on 2011-08-27 20:10 小小池 阅读(22) 评论(0) 编辑 收藏
  设计重在构思。技术在变,思想永不过时。
昵称:小小池
园龄:6年9个月
粉丝:0
关注:0
<2011年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

搜索

 
 

常用链接

我的标签

随笔分类

随笔档案

ORM

积分与排名

  • 积分 - 24222
  • 排名 - 4343

最新评论

阅读排行榜

评论排行榜

推荐排行榜