GPU上和CPU上執行函式時間比較
阿新 • • 發佈:2019-02-05
cpu上記錄時間,用clock函式或者 QueryPerformanceFrequency(&num); QueryPerformanceCounter(&num)函式;
具體使用:QueryPerformanceFrequency(&num); QueryPerformanceCounter(&num)函式:
LARGE_INTEGER num;
double start,end,freq;
QueryPerformanceFrequency(&num);
freq=num.QuadPart;
QueryPerformanceCounter(&num);
start= num.QuadPart;
//…calculating… 程式部分 //
QueryPerformanceCounter(&num);
end= num.QuadPart;
printf("time(cpu)=%2f ms\n",(end-start)*1000/freq); 特別注意 不能寫錯格式符,不能為%d\n
ms\n", totaltime);
double start,end,freq;
QueryPerformanceFrequency(&num);
freq=num.QuadPart;
QueryPerformanceCounter(&num);
start= num.QuadPart;
//…calculating… 程式部分 //
end= num.QuadPart;
printf("time(cpu)=%2f ms\n",(end-start)*1000/freq); 特別注意 不能寫錯格式符,不能為%d\n
clock函式:
clock_t starttime,endtime;
double totaltime;
starttime=clock();
//程式部分//
endtime=clock();
totaltime=(double)((endtime-starttime)*1000/(double)CLOCKS_PER_SEC);
printf("time(CPU): %2f
GPU上記錄時間最好用cudaEvent_t start,stop;這個精度到毫秒,clock精確到秒