C# 测试程序运行时间

主要是为了检测 执行 插入数据库时候那段代码的执行时间

在网上整理收集得到,做个备注,方便以后使用。

View Code
using System.Diagnostics;


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 @ 2013-02-16 13:20  Ruicky  阅读(227)  评论(0编辑  收藏  举报