clock_t与time_t的区别及联系

clock_t

<ctime>
Clock type
Type capable of representing clock tick counts and support arithmetical operations.

This type is returned by the  clock  function of the  <ctime>  header to represent the number of clock ticks since the beginning of the program execution.

time_t

<ctime>
Time type
Type capable of representing times and support arithmetical operations.

This type is returned by the  time  function and is used as parameter by some other functions of the  <ctime>  header.

It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms.


转载:

下面转自:http://www.cnblogs.com/chenyadong/archive/2011/12/03/2274783.html

clock()返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数,而sleep(5)并不占用cpu资源,导致start1和end1返回的值一样。time(&temp)返回从CUT(Coordinated Universal Time)时间1970年1月1日00:00:00(称为UNIX系统的Epoch时间)到当前时刻的秒数。总之,用time_t计时才是人们正常意识上的秒数,而clock_t计时所表示的是占用CPU的时钟单元。



结果如下图示:


  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值