程序运行时间为0的问题
来源:互联网 发布:美橙互联 域名证书 编辑:程序博客网 时间:2024/06/06 18:37
今天为了检测自己某些功能模块的时间消耗,发现使用了好几种方法,得到的时间都是0 ,后来才发现是因为消耗的时间太少了,一般常用的方法得到的时间精度不够,下面分享一下我的学习历程。
1.一开始使用GetTickCount();,测试结果为0,具体代码:
DWORD dwStart = GetTickCount(); DWORD dwStart = timeGetTime(); m_String=getSystemName().c_str(); DWORD dwUsed = timeGetTime(); m_Time = dwUsed - dwStart;
2.使用 timeGetTime()函数,需要添加#include <Mmsystem.h>,自己测试结果为0
DWORD dwStart = timeGetTime(); //开始时间 m_String=getSystemName().c_str(); DWORD dwUsed = timeGetTime(); //结束时间 m_Time8 = dwUsed - dwStart; //消耗时间
还使用了clock()函数,也不行,最后在网上查到了一个以纳秒计的函数,1秒=10亿纳秒。总算结果测试不为零了。具体代码:
先再头文件内定义一内联函数:
inline unsigned GetCycleCount() { __asm _emit 0x0F __asm _emit 0x31 } 实际使用:
unsigned long t1,t2; t1 = (unsigned long)GetCycleCount(); //开始时间 m_String = getSystemName().c_str(); t2 = (unsigned long)GetCycleCount(); m_Time = t2-t1;
结果截图:
0 0
- 程序运行时间为0的问题
- PAT 程序运行时间问题
- 关于统计统计程序运行时间的问题
- JAVA问题总结之14-程序运行时间的测量
- 取得程序的运行时间
- 计算程序运行的时间
- 程序运行时间的测量
- 测试程序运行的时间
- 监视程序的运行时间
- 程序运行时间的测量
- 记录程序的运行时间
- 测量程序的运行时间
- 测试程序的运行时间
- 测试程序的运行时间
- 程序运行时间的测量
- 计算程序运行的时间
- 计算程序的运行时间
- 程序运行时间的控制
- QT 读写XML
- mongoDB shardKey
- Mac下常用工具软件
- windbg Conditional breakpoints 条件断点
- Xamarin 编译错误: The file "obj-Release-android-bin-package_resources" does not exist
- 程序运行时间为0的问题
- org.eclipse.wst.common.project.facet.core.xml读不到
- 安卓文件操作
- Mysql相关笔记
- 3.php工厂模式
- PHP错误提示的关闭方法
- 页面倒计时一定时间,实现跳转到另一页面
- htm、html、shtml区别
- 数据结构之队列