python – 我的函数需要负时间才能完成.世界上发生了什么?

python – 我的函数需要负时间才能完成.世界上发生了什么?,第1张

概述我主要是出于好奇而提出这个问题.我写了一些代码,这些代码正在做一些非常耗时的工作.因此,在执行我的主力函数之前,我将其包含在对time.clock()的几次调用中.它看起来像这样: t1 = time.clock()print this_function_takes_forever(how_long_parameter = 20)t2 = time.clock()print t2 - t1 我主要是出于好奇而提出这个问题.我写了一些代码,这些代码正在做一些非常耗时的工作.因此,在执行我的主力函数之前,我将其包含在对time.clock()的几次调用中.它看起来像这样:

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 – 我的函数需要负时间才能完成.世界上发生了什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1195254.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存