【C++】测试时间

版权声明:转载请注明出处 http://blog.csdn.net/TwT520Ly https://blog.csdn.net/TwT520Ly/article/details/82971374

为了精准的获取程序块的运行时间,使用sys/time.h进行时间测试。

struct timeval start;
struct timeval end;
unsigned long Time = 0;

gettimeofday(&start, NULL);
...
gettimeofday(&end, NULL);

Time = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);

上述程序是获取程序运行的微秒。

猜你喜欢

转载自blog.csdn.net/TwT520Ly/article/details/82971374
今日推荐