cpu计算时间:
#include <stdio.h>
#include <Windows.h>
DWORD start2, end2;
start2 = GetTickCount();
//需要计算时间的程序
end2 = GetTickCount();
printf("cpu time: %d ms\n", end2 - start2);
gpu计算时间:
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
//需要计算时间的程序
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float time;
cudaEventElapsedTime(&time, start, stop);
printf("gpu time = %3.1f ms\n", time);