【C&C++】查看代码运行时间
查看代码运行时间有助于更好地优化项目代码
1. Windows平台
windows平台下有两种方式,精度有所不同,都需要包含<windows.h>头文件
1) DWORD GetTickCount(void); 返回毫秒数
官方文档:(3/28/2014) msdn
For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at zero on boot and then counts up from there.
For debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted. This enables code that uses GetTickCount to be easily tested for correct overflow handling.
该函数有几点需要注意:
a) The elapsed time is stored as a DWORD value. Therefore, the time will rollover to zero if the system is run continuously for 49.7 days
b) For debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted.
c) On the STMicro platform, the time returned by GetTickCount includes a ~0.014% time drift, which is by design. This translates to a time lag of approximately 1 second every 2 hours.
d) 实际使用中,发现该函数相当不精确,对于运行时间只有10毫秒以内的代码段,经常显示0,百度百科中有讲到这个函数并非实时发送,而是由系统每18ms发送一次,因此其最小精度为18ms。当需要有小于18ms的精度计算时,应使用StopWatch或其它方法进行。连续触发200次,实测下来,最小间隔在15ms。实际状况应该是系统每秒触发64次,间隔在15、16ms之间波动。
2) BOOL WINAPI QueryPerformanceCounter( _Out_ LARGE_INTEGER *lpPerformanceCount); 返回微秒数
官方文档:msdn
Retrieves the current value of the performance counter, which is a high resolution (<1us) time stamp that can be used for time-interval measurements.
【C&C++】查看代码运行时间的更多相关文章
- 用SWD调试接口测量代码运行时间 ( SWO )
用SWD调试接口测量代码运行时间 关于时间测量的种种问题 在嵌入式中,我们经常需要测量某段代码的执行时间或测量事件触发的时间,常规的思路是: 1:在测量起始点,反转电平2:在测量结束点,再次反转电平 ...
- C#如何测试代码运行时间
1.System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 // 需要测试 ...
- svn查看代码作者的命令
svn blame **.java | grep ** svn查看代码作者的命令
- 使用console进行 性能测试 和 计算代码运行时间(转载)
本文转载自: 使用console进行 性能测试 和 计算代码运行时间
- C# 测试代码运行时间
一.新建一个控制台程序项目Test.exe using System; using System.Collections.Generic; using System.Linq; using Syste ...
- 查看语句运行时间异常的原因(SQLServer)
转载:http://www.cnblogs.com/fygh/archive/2012/01/17/2324926.html 查看语句运行时间异常的原因(SQLServer) 经常有开发同事反映如 ...
- clock_gettime测代码运行时间
//函数原型: // long clock_gettime (clockid_t which_clock, struct timespec *tp); //参数列表: // CLOCK_REALTIM ...
- C# 精准获取代码运行时间
纯粹转载,转载请注明参考链接及作者! 参考链接:http://www.cnblogs.com/ret00100/archive/2010/08/06/1793680.html,作者:博客园 大佬辉 ...
- Objective-C 计算代码运行时间
今天看到一篇关于iOS应用性能优化的文章,其中提到计算代码的运行时间,觉得非常有用,值得收藏.不过在模拟器和真机上是有差异的,以此方法观察程序运行状态,提高效率. 第一种:(最简单的NSDate) N ...
随机推荐
- struts2一个实例中遇到的问题
今天实现了一个登录功能的Struts2小程序. 期间遇到了许多问题,记忆犹新的是 (1)新版本的tomcat9和eclipse Neon Release (4.6.0) 发生了冲突,启动服务器的时候老 ...
- VS2015 C#6.0 中的那些新特性(转自http://www.cnblogs.com/henryzhu/p/new-feature-in-csharp-6.html)
自动属性初始化 (Initializers for auto-properties) 以前我们是这么写的 为一个默认值加一个后台字段是不是很不爽,现在我们可以这样写 只读属性的初始化(Getter-o ...
- How to avoid Over-fitting using Regularization?
http://www.mit.edu/~9.520/scribe-notes/cl7.pdf https://en.wikipedia.org/wiki/Bayesian_interpretation ...
- cocos2d-x CCControl控件
感谢点评与关注.欢迎转载与分享.勤奋努力,持之以恒! CCControlSlider 滑动条 void HelloWorld::myInit10() { CCSize size = CCDirecto ...
- 打开或者 关闭 php 的错误报告
一般线上的环境,我会 php的报错信息屏蔽掉,php.ini 设置的办法 如下: display_errors = Off error_reporting = E_ALL 在代码中,可以这样~~: e ...
- HR_ROS 节点信息
https://stackoverflow.com/questions/24638063/install-node-serialport-module-on-arm-linux https://blo ...
- Data Structure Binary Tree: Convert a given tree to its Sum Tree
http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...
- js 实现滑块效果
var dd = $(".drag_bott").removeAttr('id').last().attr('id','drag_bott'); var drag = docume ...
- php使用mysql数据库时中文不显示或显示异常解决方法
如果出现标题所述问题,需从四个层面解决问题 1 项目文件是否为utf8编码 右键项目文件->properties->Resource->Text file encoding-> ...
- JSON与AJAX的使用
主要内容: 一.JSON数据 二.JSON字符串与Java对象的相互转换 三.JSON字符串与JavaScript对象的相互转换 四.AJAX异步加载 一.JSON数据 1.JSON语法规则: 2.J ...