在linux中用C语言计时可以用很多方法。
1. 如果是想使用秒级别的技术,可用使用C语言库<time.h>自带的clock()进行计时。如:
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
clock_t start = clock();
//do some process here
clock_t end = (clock() - start)/CLOCKS_PER_SEC;
cout<<"time comsumption is "<<end<<endl;
}
以上方法只能用于秒级别的计时。
2.如果想使用毫秒级别的计时可以使用2种方法。一种是使用linux的系统库<sys/time.h>,一种是使用CUDA的cutil的库。
A. 如果使用linux的系统库,则可以使用如下方法:
#include <sys/time.h>
int main()
{
timeval starttime,endtime;
gettimeofday(&starttime,0);
//do some process here
gettimeofday(&endtime,0);