private void ShowRunTime()
{
TimeSpan ts1 = Process.GetCurrentProcess().TotalProcessorTime;
Stopwatch stw = new Stopwatch();
stw.Start();
int Circles = 1000;
for (int i = 0; i < Circles; ++i)
{
Console.WriteLine(i.ToString());
}
double Msecs = Process.GetCurrentProcess().TotalProcessorTime.Subtract(ts1).TotalMilliseconds;
stw.Stop();
Console.WriteLine(string.Format("循环次数:{0} CPU时间(毫秒)={1} 实际时间(毫秒)={2}", Circles, Msecs, stw.Elapsed.TotalMilliseconds, stw.ElapsedTicks));
Console.WriteLine(string.Format("1 tick = {0}毫秒", stw.Elapsed.TotalMilliseconds / stw.Elapsed.Ticks));
}

核心代码:

Stopwatch stw = new Stopwatch();
stw.Start();

string aa=  wactch.ElapsedMilliseconds.ToString();

string aa=  stw.Elapsed.TotalMilliseconds.ToString();

stw.Stop();

C#实现测量程序运行时间及cpu使用时间的更多相关文章

  1. C#测量程序运行时间及cpu使用时间

    转载:http://www.cnblogs.com/yanpeng/archive/2008/10/15/1943369.html 对一个服务器程序想统计每秒可以处理多少数据包,要如何做?答案是用处理 ...

  2. C#测量程序运行时间及cpu使用时间实例方法

    private void ShowRunTime() { TimeSpan ts1 = Process.GetCurrentProcess().TotalProcessorTime; Stopwatc ...

  3. C# 测试程序运行时间和cpu使用时间

    方法一 Stopwatch类测试程序运行时间和cpu使用时间 添加命名空间using System.Diagnostics;使用实例如下 private Stopwatch sw = new Stop ...

  4. C# 测量程序运行时间

    using System.Diagnostics; Stopwatch watch = new Stopwatch(); watch.Start(); /* 需要测量运行时间的程序 */ watch. ...

  5. 测量C++程序运行时间

    有个很奇怪的现象,我自认为写得好的文章阅读量只有一百多,随手写的却有一千多--要么是胡搞,要么是比较浅显.纵观博客园里众多阅读过万的文章,若非绝世之作,则必为介绍入门级知识的短文.为了让我的十八线博客 ...

  6. [daily]使用rdtsc指令,测量程序的运行速度 [转]

    原文地址:http://blog.chinaunix.net/uid-24774106-id-2779245.html 最近搞架构,一直在讨论.听人提到,自行科普了一下,先转发,mark.有机会深入学 ...

  7. C/C++下测量函数运行时间

    C/C++下测量函数运行时间 time.h介绍 C/C++中的计时函数是clock(),而与其相关的数据类型是clock_t. clock_t clock( void ); 这个函数返回从" ...

  8. VC++程序运行时间测试函数

    0:介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如我们通过记录函数或者算 ...

  9. C++程序运行时间-ZZ

    [15.5.25]贴一段实用的代码,linux下跑过. #include <stdio.h> /* printf */ #include <time.h> /* clock_t ...

随机推荐

  1. cocos2dx之触摸事件

    要使精灵能够接收到触摸事件,无非要做三件事. 注册触摸事件; 接收触摸事件; 处理触摸事件. 下面就从这三点出发,来了解一下精灵如何响应触摸事件. 1.注册触摸事件 精灵类Poker继承Sprite和 ...

  2. Gradle一分钟实现Spring-MVC

    前提: 1,已安装JDK 2, 有Intellij IDEA 3, 已安装Gradle 一分钟实现步骤: 1,mkdir Spring-MVC;cd Spring-MVC2,gradle init3, ...

  3. HTML5 canvas 中的线条样式

    线条样式属性 lineCap        设置或返回线条的结束端点样式 butt         默认.向线条的每个末端添加平直的边缘. round         向线条的每个末端添加圆形线帽. ...

  4. 一个读取propeties配置文件的工具类,线程安全的

    public class ConfigUtil { private static Map<String,Properties> map = new HashMap<String,Pr ...

  5. 限制对比度自适应直方图均衡(Contrast Limited Adaptive histgram equalization/CLAHE)

    转自:http://www.cnblogs.com/Imageshop/archive/2013/04/07/3006334.html 一.自适应直方图均衡化(Adaptive histgram eq ...

  6. recovery编译汉化源码开源地址

    本Recovery基于xiaolu开源的不完全汉化版源码,进行完全汉化,并合并Philz的最新源码. 汉化耗费我将近一整天的精力,纯手打,可能有遗漏或翻译不准的地方,请到微博反馈 本Rec完全开源,便 ...

  7. 剑指offer之O(1)算法删除指针所指向的节点

    题目如图: 1.把要删除pToBeDeleted的节点的后面节点覆盖点要删除的节点pToBeDeleted 2.要考虑如果删除的节点是最后一个节点怎么办 3.要考虑如果总共只有一个节点,删除的是头结点 ...

  8. nmap svn

    http://stackoverflow.com/questions/13296361/nmap-and-svnlib-client-not-working-together http://nmap. ...

  9. ural 1353. Milliard Vasya's Function

    http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...

  10. XJOI网上同步测试DAY14 T1

    思路:线段树维护最短路 #include<cstdio> #include<cmath> #include<iostream> #include<algori ...