首页 > 其他 > 详细

VC 测试一段程序的运行时间 精确到ms

时间:2016-03-09 15:31:25      阅读:152      评论:0      收藏:0      [点我收藏+]

分三个步骤

1:声明变量

LARGE_INTEGER litmp;
_int64 QPart1,QPart2;
double dfMinus,dfFreq, dfTim;
QueryPerformanceFrequency(&litmp);

2 在判断时间的开始位置 开始计时

dfFreq=(double) litmp.QuadPart;
QueryPerformanceCounter(&litmp);
QPart1=litmp.QuadPart;

3 在判断结束位置 读取运行时间

QueryPerformanceCounter(&litmp);
QPart2=litmp.QuadPart;
dfMinus=(double)(QPart2-QPart1);
dfTim = dfMinus/dfFreq*1000;
//显示时间
CString msg4="时间:",msg3,msg5="毫秒";
msg3.Format("%10.9f",dfTim);
CString st = msg4+msg3+msg5;

 

st就是最终输出的 运行时间

VC 测试一段程序的运行时间 精确到ms

原文:http://www.cnblogs.com/LJWJL/p/5257897.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!