C和C++篇——各種各樣的函式

封霸業於狼居胥發表於2020-10-20

時間函式

#include <windows.h>                //取系統時間
LARGE_INTEGER tick, begin, end;
QueryPerformanceFrequency(&tick);	//取計數器頻率
QueryPerformanceCounter(&begin);	//取初始硬體定時器計數
//中間程式執行//
QueryPerformanceCounter(&end);      //獲得終止硬體定時器計數
cout << "計數器頻率:" << tick.QuadPart << "Hz" << endl;
cout << "時鐘計數  :" << end.QuadPart - begin.QuadPart << endl;
cout << setprecision(6) << (end.QuadPart - begin.QuadPart) / double(tick.QuadPart) << "秒" << endl;

在這裡插入圖片描述

延時迴圈

#include<ctime>
不啦不啦
float secs;
cin>>secs;
clock_t delay=secs*CLOCK_PER_SEC;
clock_start=clock();                
while(clock()-start<delay)          
     ;                               //空語句

相關文章