Difference between time_t and clock_t
2012-03-21 10:11
531 查看
The example:
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.
#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.
相关文章推荐
- Difference between CLOCK_REALTIME and CLOCK_MONOTONIC
- Difference between physically exclusive,logically exclusive and async clock groups
- OSS存储上遇到The difference between the request time and the current time is too large.
- Get the Degree of Angle Between Hour and Minute Hand of a Clock at Anytime
- Difference between Unix Time and UTC time
- 亚马逊S3 - The difference between the request time and the current time is too large.
- Get the Degree of Angle Between Hour and Minute Hand of a Clock at Anytime
- The difference between the request time and the current time is too large.阿里云oss上传图片报错
- The difference between CLOCK_MONOTONIC and CLOCK_REALTIME
- The difference between the request time and the current time is too large.
- [Error Code]:RequestTimeTooSkewed, [Message]:The difference between the request time and the current
- What is the Difference Between http and https?
- Difference Between String , StringBuilder And StringBuffer Classes With Example : Java
- Difference between parameter COMPATIBLE and OPTIMIZER_FEATURES_ENABLE
- What is the difference between an EXE and a DLL?
- What is the difference between tag and branch-id?
- Difference between Linearizability and Serializability
- The difference between (()) and ().
- Difference between List and Set in Java Collection
- What is the difference between user level threads and kernel level threads?