clock()和gettimeofday()
#include <iostream>
#include <time.h>
#include <sys/time.h>
using namespace std;
int main()
{
int counter = 0;
clock_t start, finish;
double totaltime;
start = clock();
for(int i = 0; i< 100000;i++)
{
counter=1;
}
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
cout << "clock " << totaltime << "s" << endl;
struct timeval sTime, eTime;
gettimeofday(&sTime, NULL);
for(int j = 0; j< 100000;j++)
{
counter=1;
}
gettimeofday(&eTime, NULL);
long exeTime = (eTime.tv_sec-sTime.tv_sec)*1000000+(eTime.tv_usec-sTime.tv_usec);
cout << "gettimeofday "<< exeTime << "us" << endl;
return 0;
}