Linux平台
#include<iostream>
#include<time.h>
using namespace std;
int main()
{
clock_t start,finish;
double totaltime;
start = clock();
//your code
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
cout<< "Time used " << totaltime << "s" <<endl;
}
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
unsigned long nCount = 0;
nCount = GetTickCount();
//your code
nCount = GetTickCount() - nCount;
cout << "Time used: " << nCount << "ms" << endl;
return 0;
}