python神奇时钟项目_FreeBSD上的Python时钟功能

While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156

The time.time() function works properly but I need a something with a slightly higher resolution.

Does anyone the C function it's bound to and if there is an alternative high resolution timer?

I'm not profiling so the TimeIt module is not really appropriate here.

解决方案

time.clock() returns the processor time. That is, how much time the current process has used on the processor. So if you have a Python script called "clock.py", that does import time;print time.clock() it will indeed print about exactly the same each time you run it, as a new process is started each time.

Here is a python console log that might explain it to you:

>>> import time

>>> time.clock()

0.11

>>> time.clock()

0.11

>>> time.clock()

0.11

>>> for x in xrange(100000000): pass

...

>>> time.clock()

7.7800000000000002

>>> time.clock()

7.7800000000000002

>>> time.clock()

7.7800000000000002

I hope this clarifies things.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值