//获取比較准确是程序执行时间


#include<iostream>
#include<windows.h>
using namespace std;

int main(void)
{       


    system("color F0"); 


    cout.setf(ios::fixed);                     
    cout.setf(ios::showpoint);
    cout.precision(10);  


//获取时钟频率
    LARGE_INTEGER m_liPerfFreq={0};
    QueryPerformanceFrequency(&m_liPerfFreq); 

//获取初始计数
    LARGE_INTEGER m_liPerfStart={0};
    QueryPerformanceCounter(&m_liPerfStart);

//測试代码的位置
    for(int ix=0;ix<100000;ix++){
         cout<<" ";
    }

//获取最后计数
    LARGE_INTEGER liPerfNow={0};
    QueryPerformanceCounter(&liPerfNow);

//计算时间

    long long time=( ((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000)/m_liPerfFreq.QuadPart);


    cout<<time<<endl;





    system("pause");
    return 0;
}



相关文章:

  • 2021-12-13
  • 2021-09-19
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2021-09-01
  • 2022-12-23
  • 2021-07-16
  • 2021-08-20
  • 2021-12-19
相关资源
相似解决方案