Windows10/Linux CentOS环境下C++测时方法

Win10下:

#include
clock_t start,end;
start = clock();//(int ms)
end = clock();//(int ms)
cout<<"time:"<<end-start<<"ms"<<endl;

Linux CentOS下:

#include
struct timeval start,end;
gettimeofday(&start, NULL);
gettimeofday(&end, NULL);
double sec = end.tv_sec - start.tv_sec;
double usec = end.tv_usec - start.tv_usec;
cout<<"time:"<<sec*1000 + usec / 1000<<"ms"<<endl;

你可能感兴趣的:(Windows10/Linux CentOS环境下C++测时方法)