私は同じアルゴリズムのcudaとcppの実装を持っています。cudaとC++コードに匹敵するタイム計測を行う方法
C言語で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);
++私は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);
これはgood-同等の結果を得るための正しい方法ですCUDAに私はイベントとtimemeasurementを作りますか?
ありがとうございます!
これが十分であれば、比較のためには問題ありません(ミリ秒の精度を見て、実行時間を長くしないでください)。 C++の標準的な方法でC++ 11以上のものを望むなら、[std :: chrono](http://en.cppreference.com/w/cpp/chrono) - 長期間の 'steady_clock'(システムを避けるC++の標準ライブラリとOSが提供できる精度のような精度のために 'high_resolution_clock'を使用しています。 –
このスレッドも参照してください:http://stackoverflow.com/questions/728068/how-to-calculate-a-time-difference-in-c – Rames