Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(Python)time.clock()的意外输出_Python_Linux_Time_Clock - Fatal编程技术网

(Python)time.clock()的意外输出

(Python)time.clock()的意外输出,python,linux,time,clock,Python,Linux,Time,Clock,理解time.clock()的输出时遇到问题: Linux 3.5.0-17-generic#28 Ubuntu SMP周二10月9日19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux 分销商ID:LinuxMint 描述:Linux Mint 14 Nadia 发布日期:14 代号:娜迪亚 Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help"

理解time.clock()的输出时遇到问题:

Linux 3.5.0-17-generic#28 Ubuntu SMP周二10月9日19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux 分销商ID:LinuxMint 描述:Linux Mint 14 Nadia 发布日期:14 代号:娜迪亚

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
Python 2.7.3(默认,2012年9月26日21:51:14)
[GCC 4.7.2]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从时间导入时钟、睡眠、时间
>>>而对:睡眠(1);打印时钟()
... 
0.03
0.03
0.03
0.03
0.03
^CTraceback(最近一次通话最后一次):
文件“”,第1行,在
键盘中断
>>>而对:睡眠(1);打印时间()
... 
1382460160.37
1382460161.37
1382460162.37
1382460163.38
1382460164.38
^CTraceback(最近一次通话最后一次):
文件“”,第1行,在
键盘中断
#…等几分钟。。。
>>>而对:睡眠(1);打印时钟()
... 
0.04
0.04
0.04
0.04
0.04
0.04
^CTraceback(最近一次通话最后一次):
文件“”,第1行,在
键盘中断
>>> 
$cat test.py
#! /usr/bin/python
从时间导入睡眠、时间、时钟
尽管如此:
打印时钟(),时间()
睡眠(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(最近一次通话最后一次):
文件“test.py”,第7行,在
睡眠(1)
键盘中断

我显然遗漏了一些明显的东西?

在Linux系统上,
time.clock()
返回“处理器时间”,而不是“墙时间”。在Linux系统上,
time.clock()
返回“处理器时间”,而不是“墙时间”。在Linux系统上,
time.clock()
返回“处理器时间”,而不是“墙时间”.

在Linux系统上,
time.clock()
返回“处理器时间”,而不是“墙时间”。

@CoreyGoldberg-是的,我查看了所有与time.clock()有关的各种问题,包括这个问题,但我没有看到任何解释为什么time.clock()会重复返回相同(意外)值的方法,一秒接一秒,看我的答案。这是因为您没有使用太多的处理器周期。。所以没有太多的处理器时间使用。。。迷失在粒度中。好的,明白了。我想这个函数的名字和它与其他平台不同的工作原理让我很反感。谢谢。@CoreyGoldberg-是的,我看了所有与time.clock()有关的问题,包括那一个,但我没有看到任何解释为什么time.clock()会一秒接一秒地重复返回相同(意外)值的问题。请看我的答案。这是因为您没有使用太多的处理器周期。。所以没有太多的处理器时间使用。。。迷失在粒度中。好的,明白了。我想这个函数的名字和它与其他平台不同的工作原理让我很反感。谢谢。@CoreyGoldberg-是的,我看了所有与time.clock()有关的问题,包括那一个,但我没有看到任何解释为什么time.clock()会一秒接一秒地重复返回相同(意外)值的问题。请看我的答案。这是因为您没有使用太多的处理器周期。。所以没有太多的处理器时间使用。。。迷失在粒度中。好的,明白了。我想这个函数的名字和它与其他平台不同的工作原理让我很反感。谢谢。@CoreyGoldberg-是的,我看了所有与time.clock()有关的问题,包括那一个,但我没有看到任何解释为什么time.clock()会一秒接一秒地重复返回相同(意外)值的问题。请看我的答案。这是因为您没有使用太多的处理器周期。。所以没有太多的处理器时间使用。。。迷失在粒度中。好的,明白了。我想这个函数的名字和它与其他平台不同的工作原理让我很反感。谢谢