随笔 - 132  文章 - 51  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(7)

随笔分类

随笔档案

文章分类

文章档案

cocos2d-x

OGRE

OPenGL

搜索

  •  

最新评论

阅读排行榜

评论排行榜

在编程过程中经常遇到测试一段程序执行时间的问题,下面给出两种测试代码段执行时间的方法以供参考。

第一种方法:低精度,GetTickCount()函数的精度只有10ms,所以如果程序执行时间小于10ms,不能使用该函数
DWORD Milliseconds_Parser_Start;
DWORD Milliseconds_Parser_End;
Milliseconds_Parser_Start = ::GetTickCount();

// 待测试代码段

Milliseconds_Parser_End = ::GetTickCount();
TCHAR debugStr[256];
_stprintf(szDebug, "item: %d milin sec \n",Milliseconds_Parser_End - Milliseconds_Parser_Start);
OutputDebugString(debugStr);

第二种方法:高精度
LARGE_INTEGER t_freqency;
QueryPerformanceFrequency(&t_freqency);
float f_countDiff2Milisecond = float(1000.0/t_freqency.QuadPart);

LARGE_INTEGER start;
LARGE_INTEGER end;
QueryPerformanceCounter(&start);


// 待测试代码段

QueryPerformanceCounter(&end);
TCHAR debugStr[256];
_stprintf(debugStr, _T("item: %f milin sec \n"),(end.QuadPart - start.QuadPart) * f_countDiff2Milisecond );
OutputDebugString(debugStr);

 

CSDN博客:http://blog.csdn.net/rabbit729/archive/2010/05/22/5616976.aspx

posted on 2010-08-18 14:49 风轻云淡 阅读(523) 评论(0)  编辑 收藏 引用 所属分类: C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理