精确计算程序运行的时间

#include <iostream.h>   
#include <windows.h>   
  
void main()  
{  
  
    LARGE_INTEGER Freq;  
    LARGE_INTEGER Count1, Count2;  
    QueryPerformanceFrequency(&Freq);  //调用API函数,  这个API函数可是优先级0的函数啊.    
  
    QueryPerformanceCounter(&Count1);  //获取时间1   
  
    //测试程序;   
    Sleep(123);  
  
    QueryPerformanceCounter(&Count2);  //获取时间2   
      
    double d = (double)(Count2.QuadPart - Count1.QuadPart) / (double)Freq.QuadPart * 1000.0;  
  
    cout<<"count1 = "<<(double)Count1.QuadPart<<endl;  
    cout<<"count2 = "<<(double)Count2.QuadPart<<endl;  
  
    cout<<"run time is :"<<d<<" ms "<<endl;  
  
    cout<<"system timer frequence :"<<(double)Freq.QuadPart<<" Hz"<<endl;  
}  

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页