【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 ...
随机推荐
- Python 字符串拼接、格式化输出、深浅复制
拼接:"+"号(同类型可拼接) >>>li = [1,2] >>>li + li [1,2,1,2] >>>li*2 [1,2 ...
- SQL SERVER 2008递归
tab1 表结构: create tab1 ( id int primary key identity(1,1), parentid int not null, name varchar(25) ) ...
- 【CodeM初赛B轮】A 贪心
[CodeM初赛B轮]A 题目大意:给你一棵树,起初所有点都是白色的,你每次都能选择一个白点i,将这个点i到根路径上的所有到i的距离<k[i]的点都染成黑色(根和i也算,已经被染成黑色的点还是黑 ...
- City Game(最大子矩阵)
Bob is a strategy game programming specialist. In his new city building game the gaming environment ...
- First non repeating word in a file? File size can be 100GB.
1 solution 1 1.1 数据结构 一个Hashmap和一个双向链表.如果想要快速获取first,并且只遍历一次,那么就要想到双向链表和HashMap的组合. 链表可以保证第一个在head处, ...
- 北京君正集成电路的Newton平台--穿戴式
版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/hellomxj1/article/details/25324125 Newton1开发平台 • 很适合 ...
- crontab定时任务写法记录
基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...
- androidAndroid开发学习--Ionic+Cordova 环境搭建
我们看 Ionic 能给我们提供什么? 一个样式库,你可以使用它 来 装饰你的 HTML 网页 ,看起来 想 移动程序的 界面,什么 header .content.footer.grid.list ...
- DAS、NAS、SAN
目前磁盘存储市场上,存储分类(如下表一)根据服务器类型分为:封闭系统的存储和开放系统的存储,封闭系统主要指大型机,AS400等服务器, 开放系统指基于包括Windows.UNIX.Linux等操作系统 ...
- Java基础教程:多线程基础(1)——基础操作
Java:多线程基础(1) 实现多线程的两种方式 1.继承Thread类 public class myThread extends Thread { /** * 继承Thread类,重写RUN方法. ...