示例代碼:
long begin,end;
double time;
begin = clock();
{
//查看代碼
}
end = clock();
time = (double)(end - begin) / CLOCKS_PER_SEC;
Logger->Info( "%f seconds\n", time );
其他參考:
#include<iostream>
include<windows.h>
using namespace std;
int main()
{
DWORD start_time=GetTickCount();
{
//此處為被測試代碼
}
DWORD end_time=GetTickCount();
cout<<"The run time is:"<<(end_time-start_time)<<"ms!"<<endl;//輸出運行時間
return 0;
}
#include<iostream>
#include<time.h>
using namespace std;
int main()
{
clock_t start_time=clock();
{
//被測試代碼
}
clock_t end_time=clock();
cout<< "Running time is: "<<static_cast<double>(end_time- start_time)/CLOCKS_PER_SEC*1000<<"ms"<<endl;//輸出運行時間
return 0;
}
posted on 2013-10-22 08:20
王海光 閱讀(838)
評論(0) 編輯 收藏 引用 所屬分類:
C++