.NET计时器的使用-Stopwatch类
2024-08-29 22:05:05
作用:
微软提供的常用于统计时间消耗的类,作为一个固定的API接口供大家使用。
先看代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading; namespace StopWatchDemo
{
class Program
{
static void Main(string[] args)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); int icount = ;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
icount = i + j;
}
} stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed.TotalMilliseconds);
}
}
}
代码简化:
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
与下面是相同用法
Stopwatch stopwatch = Stopwatch.StartNew();
该类Stopwatch定义了一个静态的方法,用于开启计时器。
最新文章
- 设计模式C#合集--抽象工厂模式
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(48)-工作流设计-起草新申请
- Android Ant批量打包
- ASP.NET Application_Error错误日志写入
- 17.1.4 Replication and Binary Logging Options and Variables 复制和Binary logging 选项和变量
- slime+sbcl for common lisp
- C与C++ 无参函数的区别
- D3.js:交互式操作
- js代码大全(各种方法、属性)《转载》
- MVC页面扩展方法 单例模式
- mongoDB 文档操作_增
- [转]OpenShift 集群搭建指南
- Docker registry垃圾回收
- 八大排序算法——插入排序(动图演示 思路分析 实例代码java 复杂度分析)
- 【leetcode】27-RemoveElement
- Java基础-算术运算符(Arithmetic Operators)
- gulp入门实践
- FasterRCNN目标检测实践纪实
- mongodb 两台互为主从
- flowable EngineConfiguration的实现分析(2)