.NET: C#: StopWatch
StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very useful.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace StopWatchTest
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
string s = string.Empty;
StringBuilder sb = new StringBuilder();
;
sw.Start();
; i < ticks; i++) s += "a";
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine("string append 'a' {0} times using time in time: {1}, in milliSeconds: {2}, ticks: {3}", ticks.ToString(), ts.ToString(), ts.Milliseconds.ToString(), ts.Ticks.ToString());
sw.Restart();
; i < ticks; i++) sb.Append("a");
sw.Stop();
//ts = sw.Elapsed;
Console.WriteLine("StringBuilder append 'a' {0} times using time in time: {1}, in milliSeconds: {2}, ticks: {3}", ticks.ToString(), sw.Elapsed.ToString(), sw.ElapsedMilliseconds.ToString(), sw.ElapsedTicks.ToString());
}
}
}
.NET: C#: StopWatch的更多相关文章
- java stopwatch 功能
C#中有一个stopwatch的功能,主要是用来监测程序执行时间的.java之前一直都在用如下方式完成: public static void main(String[] args) { long s ...
- 计时器StopWatch示例
计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getS ...
- 监测程序运行的时间,stopWatch
ArrayList arrInt = new ArrayList(); //用stopwatch来计时 运行的时间 Stopwatch watch = new Stopwatch(); watch.S ...
- [转]使用Stopwatch类实现高精度计时
对一段代码计时同查通常有三种方法.最简单就是用DateTime.Now来进行比较了,不过其精度只有3.3毫秒,可以通过DllImport导入QueryPerformanceFrequency和Quer ...
- Stopwatch 类
Stopwatch 为计时器的实现. 主要属性方法 属性和方法 说明 static GetTimestamp() 如果Stopwatch使用高分辨率的性能计数器,则返回该计数器的当前值:如果Stopw ...
- Mini projects #3 ---- Stopwatch: The Game
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- C# StopWatch的使用
在做项目的时候,需要输出数据库操作的耗时,自己写了个方法.老大看到后,奇怪我为什么不用现成的.才知道有StopWatch这个类. 属性 名称 说明 Elapsed 获取当前实例测量得出的总 ...
- 使用.net Stopwatch class 来分析你的代码
当我们在调试,优化我们的代码的时候,想知道某段代码的真正的执行时间,或者我们怀疑某段代码,或是某几段代码执行比较慢, 需要得到具体的某段代码的具体执行时间的时候.有一个很好用的类Stopwatch. ...
- 一个简单的任务执行时间监视器 StopWatch
有时我们在做开发的时候需要记录每个任务执行时间,或者记录一段代码执行时间,最简单的方法就是打印当前时间与执行完时间的差值,然后这样如果执行大量测试的话就很麻烦,并且不直观, 如果想对执行的时间做进一步 ...
- C# 检测程序运行时间的方法,Stopwatch类
//需要引用命名空间,System.Diagnostics Stopwatch watch = new Stopwatch(); //实例化一个计时器 watch.Start(); //开始计时 #r ...
随机推荐
- 【转】android中最好的瀑布流控件PinterestLikeAdapterView
[源地址]http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0919/1696.html 之前我们介绍过一个开源的瀑布流控件Stag ...
- 【转】 使用Redis的Pub/Sub来实现类似于JMS的消息持久化
http://blog.csdn.net/canot/article/details/52040415 关于个人对Redis提供的Pub/Sub机制的认识在上一篇博客中涉及到了,也提到了关于如何避免R ...
- json格式的转换为json字符串函数
function toJSON(object){ var type = typeof object; if ('object' == type) { if (Array == object.const ...
- CSS :before和:after (转)
前几天的晚上较全面的去看了下css的一些文档和资料,大部分的样式运用都没什么大问题了,只是有些许较陌生,但是也知道他们的存在和实现的是什么样式.今天主要想在这篇学习笔记中写的也不多,主要是针对:bef ...
- oracle中截取某个字符前面和后面的值
创建测试表及数据 create table test(name varchar2(10)); insert into test values ('2-15');insert into test val ...
- ligerui ligerTip气泡提示信息
onAfterShowData:function(){ $('.l-grid-row-cell-inner').hover(function (){ $(this).ligerTip({content ...
- [LeetCode]题解(python):112 Path Sum
题目来源 https://leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if the tree ha ...
- The "Real" Project Plan
"I need a project plan by tomorrow morning." As project managers, that's what we hear. But ...
- 配置maven环境
第一步:安装maven,安装maven最简单,直接将maven的解压文件放入本地某目录下即可,无需手动安装 第二步:eclipse中导入maven项目后,会后错,或maven无法使用,则需要进行mav ...
- enableEventValidation是干什么的?
回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEve ...