(Python)time.clock()的意外输出 [英] Unexpected output of (Python) time.clock()
本文介绍了(Python)time.clock()的意外输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在理解time.clock()的输出时会遇到一些麻烦:
Having some trouble understanding the output from time.clock():
Linux 3.5.0-17-generic#28-Ubuntu SMP Tue Oct 9 19:31 :23 UTC 2012 x86_64 x86_64 x86_64 GNU / Linux
发行者ID:LinuxMint
描述:Linux Mint 14 Nadia
版本:14
代号:nadia
Linux 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux Distributor ID: LinuxMint Description: Linux Mint 14 Nadia Release: 14 Codename: nadia
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import clock, sleep, time
>>> while True: sleep(1); print clock()
...
0.03
0.03
0.03
0.03
0.03
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> while True: sleep(1); print time()
...
1382460160.37
1382460161.37
1382460162.37
1382460163.38
1382460164.38
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
# ...wait a few minutes...
>>> while True: sleep(1); print clock()
...
0.04
0.04
0.04
0.04
0.04
0.04
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>>
$ cat test.py
#! /usr/bin/python
from time import sleep, time, clock
while True:
print clock(), time()
sleep(1)
$ python test.py
0.02 1382460623.39
0.02 1382460624.39
0.02 1382460625.39
0.02 1382460626.39
0.02 1382460627.39
0.02 1382460628.39
0.02 1382460629.4
0.02 1382460630.4
0.02 1382460631.4
0.02 1382460632.4
0.02 1382460633.4
0.02 1382460634.4
0.02 1382460635.4
0.02 1382460636.4
0.02 1382460637.41
0.02 1382460638.41
0.02 1382460639.41
0.02 1382460640.41
0.02 1382460641.41
0.02 1382460642.41
0.02 1382460643.41
0.02 1382460644.41
0.02 1382460645.41
0.02 1382460646.42
0.02 1382460647.42
0.02 1382460648.42
0.02 1382460649.42
0.02 1382460650.42
^CTraceback (most recent call last):
File "test.py", line 7, in <module>
sleep(1)
KeyboardInterrupt
我显然在这里缺少明显的东西?
I'm obviously missing something obvious here?
推荐答案
在Linux系统上, time.clock()
返回处理器时间,而不是墙上时间。
on Linux systems, time.clock()
returns "processor time", not "wall time".
这篇关于(Python)time.clock()的意外输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文