win32- 函数运行速度测试
LARGE_INTEGER nFreq, t1, t2; int loop_count = 0; double dt; double time_sum = 0; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&t1); /* 要测试的函数 */ void TestFunction(); QueryPerformanceCounter(&t2); dt = (t2.QuadPart - t1.QuadPart) / (double)nFreq.QuadPart; time_sum += dt * 1000; loop_count++; // 函数跑一千次的总时间 if (loop_count == 1000) { char out8[128] = {0}; sprintf(out8, "%lf", time_sum); OutputDebugStringA(out8); loop_count = 0; time_sum = 0; }
最终以 ms 为单位,在输出窗口打印,也可以使用 std::cout 打印结果