.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 ...
随机推荐
- MVC3中几个小知识点
1.ViewBag.Name~ViewBag.name等价,即不区分大小写.在此小心,下次见到不要奇怪,不过最好还是写成一样的比较好. 2.JS字符串不允许有换行符,\'等字符,需提前处理.
- [LeetCode]题解(python):032-Longest Valid Parentheses
题目来源 https://leetcode.com/problems/longest-valid-parentheses/ Given a string containing just the cha ...
- mkdir
1,mkdir Problem: You want to use the mkdir() function from the sys/stat.h POSIX header, but you don’ ...
- sql语句操作集锦
SQL操作全集 下列语句部分是Mssql语句,不可以在access中使用. SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT ...
- 正确统计SQLServer的慢日志
RDS的一个富有吸引力的服务是为用户提供慢日志的运行状况报告.报告从不同的维度(总执行时间,总执行次数,总逻辑读,总物理读)为用户提供TOP20的SQL.RDS希望在为用户提供稳定,快速服务的同时,用 ...
- C3P0的详细配置说明
C3P0是一个开放源代码的JDBC连接池,它在lib目录中与Hibernate一起发布,包括了实现jdbc3和jdbc2扩展规范说明的Connection 和Statement 池的DataSourc ...
- Java 多线程Thread和Runnable
Thread: class MyThread extends Thread { private int ticketsCont=5; //一共有5张火车票 private String name; / ...
- Spring Boot 2 Swagger2
本文将介绍RESTful API的重磅好伙伴Swagger2,它可以轻松的整合到Spring Boot中,并与Spring MVC程序配合组织出强大RESTful API文档. 它既可以减少我们创建文 ...
- 第三篇 Replication:事务复制-发布服务器
本篇文章是SQL Server Replication系列的第三篇,详细内容请参考原文. 发布服务器是所有复制数据的源头.每一个发布服务器上可以定义多个发布.每一个发布包含一组项目(项目在同一个数据库 ...
- box2d.js
https://github.com/kripken/box2d.js/ Demo: http://kripken.github.io/box2d.js/webgl_demo/box2d.html 演 ...