t1 = time.clock()print this_function_takes_forever(how_long_parameter = 20)t2 = time.clock()print t2 - t1
这很好.我的函数正确返回,t2 – t1给了我972.29的结果,或大约16分钟.
但是,当我将代码更改为此时
t1 = time.clock()print this_function_takes_forever(how_long_parameter = 80)t2 = time.clock()print t2 - t1
我的功能仍然很好,但t2 – t1的结果是:
None-1741
我很好奇实施细节导致了什么. None和负数都让我感到困惑.它与签名类型有关吗?这怎么解释无?
解决方法 Python docs说:On Unix,return the current processor time as a floating point number expressed in seconds. The precision,and in fact the very deFinition of the meaning of “processor time”,depends on that of the C function of the same name
引用的C函数的manpage然后解释了问题:
总结Note that the time can wrap around. On a 32-bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approximately every 72 minutes.
以上是内存溢出为你收集整理的python – 我的函数需要负时间才能完成.世界上发生了什么?全部内容,希望文章能够帮你解决python – 我的函数需要负时间才能完成.世界上发生了什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)