我使用python3.6.5time.process_time()
来计算一些性能。在
以下是其官方documentation中的描述:
time.process_time() → float
Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process. It does not include time elapsed during sleep. It is process-wide by definition. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.
我用了与这个小例子相似的方法:
import time
x=0
start = time.process_time()
for x in range(100000):
performance = time.process_time() - start
print("performance: ",performance)
它根据我的机器给出了这个输出(因此我理解在另一台机器上它可能不同):
^{pr2}$1)如何将上面的值(例如,应该是执行循环所用时间的输出)转换为毫秒?我很困惑,因为文档中说它以分数秒为单位返回值。在
2)fractional seconds
是什么意思?如果它是秒浮点右边的分数,比如11.56
秒,它是0.56
,那么我怎么知道秒的值呢?在
3)我使用它来计算运行时间或性能时间。我只需要函数所花的时间。在
我已经用过了,所以请尝试not
来建议另一个函数。请澄清我过去的习惯。在
“in fractional seconds”表示“以秒为单位表示为浮点数”(与C的^{} 相反,后者返回整数秒)。在
所以,要把这个值转换成毫秒,乘以1000。在
相关问题 更多 >
编程相关推荐