测试工具:VS 2019
测试代码:
#include <iostream> #include <windows.h> using namespace std; static int x = 0; long long cont; /* 测试mian */ int main(void) { LARGE_INTEGER t1, t2, nfreq; //-- CPU高精度时间, double dt; QueryPerformanceFrequency(&nfreq); QueryPerformanceCounter(&t1); cout << "hello world!\n"; //-- 无聊的测式 //cont = 0x24030000; //while (cont--); QueryPerformanceCounter(&t2); //-- 计算时间:printf dt = (t2.QuadPart - t1.QuadPart) / (double)nfreq.QuadPart; cout << "\nrunning time :" << dt * 1000000 << "us" << endl; cout << "=== end ==="; cin.get(); // 暂停中。。。 return 0; }
运行结果:
好像也不是很准,因为每一次都有数据差别,这到底有没有参靠价值呀?