CUDA内核运行时间的测量函数
cudaEvent_t start1; cudaEventCreate(&start1); cudaEvent_t stop1; cudaEventCreate(&stop1); cudaEventRecord(start1, NULL); // 需要测时间的内核函数kernel; cudaEventRecord(stop1, NULL); cudaEventSynchronize(stop1); float msecTotal1 = 0.0f; cudaEventElapsedTime(&msecTotal1, start1, stop1);
CPU运行时间的测量函数
long start_time = GetTickCount();//记录程序运行时间 //需要测试时间的代码 long end_time = GetTickCount();//记录程序运行时间 cout << "程序段运行时间:" << (end_time - start_time) << "ms!" << endl;