C#测试程序运行时间的方法
C#测试程序运行时间的三种方法如下:
(1)Datetime
DateTime dtBegin = System.DateTime.Now;
...
DateTime dtEnnd = System.DateTime.Now;
TimeSpan dtTime = dtEnnd- dtBegin;
(2)Stopwatch
需要引用System.Diagnostics命名空间
Stopwatch sw = new Stopwatch();
sw.Start();
...
sw.Stop();
TimeSpan swTime = sw.Elapsed;
(3)Process.GetCurrentProcess()
TimeSpan gcpBegin = Process.GetCurrentProcess().TotalProcessorTime;
...
TimeSpan gcpTime = Process.GetCurrentProcess().TotalProcessorTime.Subtract(gcpBegin);
问题一:我的CPU数量是4,那计算CPU时间的话,需不需要除以4呢?
问题二:三种方法得到的时间是不同的,Datetime和Stopwatch得到的时间几乎一样,而Process.GetCurrentProcess()得到的时间远小于前两种,不是4倍关系,这又是为什么呢?
目前还没有找到答案,望高手指点一二。
C#测试程序运行时间的方法的更多相关文章
- C++中几种测试程序运行时间的方法<转>
转的地址:https://www.cnblogs.com/silentteen/p/7532855.html 1.GetTickCount()函数 原理: GetTickCount()是获取系统启动后 ...
- 【VBA】测试程序运行时间,延时方法
测试程序运行时间 Dim start As Date start = Now() Dim i As Long For i = 0 To 10000000 ' 10 million Next Debug ...
- C# 测试程序运行时间和cpu使用时间
方法一 Stopwatch类测试程序运行时间和cpu使用时间 添加命名空间using System.Diagnostics;使用实例如下 private Stopwatch sw = new Stop ...
- php测试程序运行时间和占用内存情况
php测试程序运行时间和占用内存情况: $HeaderTime = microtime(true);//参数true表示返回浮点数值 /** *CODE */ printf(" total ...
- C#中提供的精准测试程序运行时间的类Stopwatch
C#中提供的精准测试程序运行时间的类Stopwatch http://www.cnblogs.com/ret00100/archive/2010/08/06/1793680.html 在需要对程序的执 ...
- C++获取当前时间和计算程序运行时间的方法
C++获取当前时间和计算程序运行时间的方法 获取当前时间: #include <iostream> #include <Windows.h> using namespace s ...
- 三种计算c#程序运行时间的方法
三种计算c#程序运行时间的方法 第一种: 利用 System.DateTime.Now // example1: System.DateTime.Now method DateTime dt1 = S ...
- 在Windows及Linux下获取毫秒级运行时间的方法
在Windows下获取毫秒级运行时间的方法 头文件:<Windows.h> 函数原型: /*获取时钟频率,保存在结构LARGE_INTEGER中***/ WINBASEAPI BOOL W ...
- c# 三种计算程序运行时间的方法
三种计算c#程序运行时间的方法第一种:利用 System.DateTime.Now // example1: System.DateTime.Now method DateTime dt1 = Sys ...
随机推荐
- 【转】如何恶搞朋友的电脑?超简单的vbs代码
源地址:https://jingyan.baidu.com/article/d3b74d64aa1e6a1f77e609e6.html 表白源地址:https://jingyan.baidu.com/ ...
- 11、OpenCV Python 图像金字塔
__author__ = "WSX" import cv2 as cv import numpy as np # 高斯金字塔 #金字塔 原理 ==> 高斯模糊+ 降采样 #金 ...
- 6、OpenCV Python 图像模糊
__author__ = "WSX" import cv2 as cv import numpy as np #均值模糊 中值模糊 自定义模糊(卷积) #卷积原理 #均值模糊 de ...
- 模板 Trie树
模板 Trie树 code: #include <iostream> #include <cstdio> using namespace std; const int wx=2 ...
- tinkphp中的自动验证
tinkphp是国内非常流行的一个开源框架,国内大小公司都在用的框架.对于初学的好多同学感觉不太好上手,其实并没没有大家想的那么复杂.自动验证功能是thinkphp提高的一种数据验证方法,分为动态和静 ...
- git 日常使用从入门到真香
目录 git 日常使用从入门到真香 一.Git简介 二.Git常用命令 三.git操作流程 四.报错处理 git 日常使用从入门到真香 一.Git简介 Git是一个开源的分布式版本控制系统,可以有效. ...
- Codeforces - 151C 质因子分解
显然只需要能跑到第二个因子就赢了 需要特判非平凡因子 常数优化:不用求出所有因子,跑完第二个素数就行了 #include<bits/stdc++.h> using namespace st ...
- 多数据源 + Configuration中bean依赖注入顺序问题
为什么要调用方法,而不是直接autowire? 官方文档 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-da ...
- 问题:git处理中文名称时候显示为编码形式(已解决)
问题描述: Untracked files: (use "git add <file>..." to include in what will be committed ...
- vue入门----------路由配置
在使用脚手架搭建好项目后要配置路由 1.首先要安装vue-router,你可以在项目的package.json文件中的dependencies项目中添加"vue-route": & ...