操作方法
clock_t a,b; float cputime; a=time(NULL); for (intz=0;z<10000000;z++){ float f=0; for (int i = 0; i<n; ++i) f+= h_idata[i]; } b=time(NULL); cputime=(float)(b-a); printf("cuptime=%fmseconds\n",cputime);
for (intz=0;z<10000000;z++){ float f=0; for (int i = 0; i<n; ++i) f+= h_idata[i]; } 将此一段改为你所需要知道时间的程序即可,因为计算时间的精度在1s所以一些简单的程序经常需要循环很多次取平均值得到运行时间。