C ++ Chrono версия < /p>
Код: Выделить всё
main() {
auto chrono_start = std::chrono::high_resolution_clock::now();
// Some important work
while (100 iteration)
{
// some important work;
auto chrono_stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast(chrono_stop - chrono_start).count();
chrono_final += duration;
duration =0.0;
// Here useless work no need to measure ;
// starting new clock for next iteration
auto chrono_start = std::chrono::high_resolution_clock::now();
}
printf("Chrono average time %d\n",chrono_final/100);
}
< /code>
Приведенная выше хроновая версия дает неправильный ответ. Почему это дает неправильное время?main(){
cudaEventRecord(start,0);
// *Some important work*
while (100 iteration)
{
// *some important work;*
// *Work done for this iteration;*
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
float milliseconds = 0;
cudaEventElapsedTime(&averagetime, start, stop);
averagetime += milliseconds;
// Here useless work no need to measure ;
//starting new clock for next iteration
cudaEventDestroy(start); // Not necessary but still.
cudaEventDestroy(stop);
cudaEventRecord(start, 0);
}
printf("Cuda event average time %d\n", averagetime/100);
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ide-a-loop