I have a cuda and a cpp implementation of the same algorithm. In CUDA I make the timemeasurement with events:
cudaEvent_t start, stop;
float time;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0); // start time measurement
// some cuda stuff
cudaEventRecord(stop, 0); // stop time measurement
cudaEventSynchronize(stop); // sync results
cudaEventElapsedTime(&time, start, stop);
printf ("Elapsed time : %f ms\n", time);
In c++ I measure with timeofday:
struct timeval start, end;
long seconds, useconds;
float mseconds;
gettimeofday(&start, NULL);
// some work to do
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mseconds = (seconds * 1000 + useconds/1000.0) + 0.5;
printf ("Elapsed time : %f ms\n", mseconds);
Is this the correct way to get good- comparable results?
Thanks in advance!