您的位置:首页 > Web前端

Difference between time_t and clock_t

2012-03-21 10:11 531 查看
The example:

#include <iostream>
using namespace std;

int main()
{
time_t time_start, time_end;
time(&time_start);
sleep(5);
time(&time_end);
cout<<difftime(time_end, time_start)<<endl;  // 5

clock_t clock_start, clock_end;
clock_start = clock();
sleep(5);
clock_end = clock();
cout<<(clock_end-clock_start)/CLOCKS_PER_SEC<<endl;  // 0
return 0;
}


It is clear to see that time_t is used to test the real time, while clock_t is used to test the cost of CPU time, because sleep(5) don't occupy any CPU resource.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: