![]() ![]() |
|
计算程序时间的方法 | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/10/22 21:29:12 文章录入:杜斌 责任编辑:杜斌 | |
|
|
{ LARGE_INTEGER one; LARGE_INTEGER two; LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&one); for (int i = 0; i < 1000000000; i++) { } QueryPerformanceCounter(&two); cout << two.QuadPart * 1.0 / freq.QuadPart - one.QuadPart * 1.0 / freq.QuadPart << endl; } void time_two() { double timeStart = GetTickCount(); for (int i = 0; i < 10000000; i++) { } double timeEnd = GetTickCount(); cout << timeEnd - timeStart << endl; } void time_three() { time_t stime; time_t etime; time(&stime); getchar(); time(&etime); printf(\"%ld\\n\",etime - stime); } void time_four() { double begin=(double)clock()/CLK_TCK; for (int i = 0; i < 1000000000; i++) { } double end=(double)clock()/CLK_TCK; cout << end - begin << endl; } void time_five() { clock_t t1 = clock(); for (int i = 0; i < 1000000000; i++) { } clock_t t2 = clock(); cout<<\"Total time = \"<<t2-t1<<endl; } |
|
![]() ![]() |