标签:计时 运行时 lld div class time() count 运行 eof
linux
#include <sys/time.h> #include <iostream> #include <time.h> double get_wall_time() { struct timeval time ; if (gettimeofday(&time,NULL)){ return 0; } return (double)time.tv_sec + (double)time.tv_usec * .000001; } int main() { unsigned int t = 0; double start_time = get_wall_time(); while(t++ < 10e+6); double end_time = get_wall_time() ; std::cout<<"循环耗时为:"<<end_time-start_time<<"ms"; return 0; }
windows
#include <windows.h> #include <iostream> int main() { DWORD start, stop; unsigned int t = 0; start = GetTickCount(); while (t++ < 10e+6); stop = GetTickCount(); printf("time: %lld ms\n", stop - start); return 0; }
标签:计时 运行时 lld div class time() count 运行 eof
原文地址:https://www.cnblogs.com/Malphite/p/10952791.html