您的位置:首页 > 产品设计 > UI/UE

使用QueryPerformanceFrequency 计算程序执行时间

2012-07-30 13:11 429 查看
QueryPerformanceFrequency( __out LARGE_INTEGER *lpFrequency ); //返回定时器的频率

BOOL QueryPerformanceCounter(LARGE_INTEGER *lpPerformanceCount); //是返回定时器当前计数值

代码:

/////////////////////////////////////////////////
#include <iostream>
#include <windows.h>
using namespace    std;
////////////////////////////////////////////////
void main()
{
_LARGE_INTEGER time_start;    /*开始时间*/
_LARGE_INTEGER time_over;        /*结束时间*/
double dqFreq;                /*计时器频率*/
LARGE_INTEGER f;            /*计时器频率*/
QueryPerformanceFrequency(&f);
dqFreq=(double)f.QuadPart;
QueryPerformanceCounter(&time_start);
Sleep(1000);/*循环耗时*/
QueryPerformanceCounter(&time_over);
cout<<((time_over.QuadPart-time_start.QuadPart)/dqFreq)<<endl;//单位为秒,精度为1000 000/(cpu主频)微秒
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: