版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013699869/article/details/82899806
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
//省略错误判断
int main()
{
cudaEvent_t start, end;
float elapsedTime;
cudaEventCreate(&start);
cudaEventCreate(&end);
cudaEventRecord(start, 0);
for (int i = 0; i < 99999; i++)
;
cudaEventRecord(end, 0);
cudaEventSynchronize(end);
cudaEventElapsedTime(&elapsedTime, start, end);
cudaEventDestroy(start);
cudaEventDestroy(end);
std::cout << elapsedTime << "ms" << std::endl;
getchar();
return 0;
}