//計算某一段程序所花費的時間
#include<iostream>
#include<ctime>
using namespace std;
void Delay();//測試函數(shù),用來測試運行時間
int main()
{
clock_t startT, endT;
double duration;
cout<<"Start..."<<endl;
startT = clock();//獲取cpu絕對鐘數(shù)
Delay();
endT = clock();
duration = double(endT - startT)/CLOCKS_PER_SEC;//計算運行的時間,秒為單位
cout<<"程序運行花費的時間為: "<<duration<<endl;
return 0;
}
void Delay()
{
for(int i = 0;i<1000000000;i++)
{
}
return;
}
輸出.PNG