CUDA 编程,运行时间的统计
https://blog.csdn.net/QLeelq/article/details/127528370
单位为毫秒,精度为0.5微妙
单位是ms啊
cudaEvent_t start, stop;
float time;
cudaEventCreate(&start); //创建计时
cudaEventCreate(&stop); //创建计时
cudaEventRecord(start, 0); // 开始计时
cudaStatus = cudaDeviceSynchronize();
if (cudaStatus != cudaSuccess) {
fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching Kernel!\n", cudaStatus);
goto Error;
}
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
cudaEventDestroy(start); //销毁
cudaEventDestroy(stop);
printf("Lee with GPU cost %f ms\n", time);
CPU的方法是
https://blog.csdn.net/m0_37251750/article/details/102581935
单位也是ms
精度太差了,不建议使用这个方法!!!
#include<time.h>
clock_t start, end;
start = clock();
end = clock(); //结束时间
printf("Lee with CPU cost %f ms\n", (float)(end-start));