如何以毫秒为单位计算 python 的 "time.process_time()" 的 return 值
How to compute the return value of python's "time.process_time()" in milliseconds
我正在使用 python 3.6.5 time.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)
根据我的机器给出了这个输出(所以我知道它在另一台机器上可能不同):
performance: 0.051401815000000003
1) 如何将上述值(以执行循环的运行时间为例的输出)转换为毫秒?我很困惑,因为文档说它 returns 以小数秒为单位的值。
2) fractional seconds
是什么意思?如果是秒的浮点数右边的小数,比如说11.56
秒,就是0.56
,那我怎么知道秒的值呢?
3) 我用它来计算运行时间或表演时间。我只需要函数花费的时间。
我已经用过了,所以请尝试 not
建议其他功能。请澄清我对我的习惯。
"in fractional seconds" 表示 "in seconds represented as a floating-point number"(相对于 C 的 time
,例如 returns 整数秒)。
因此,要将值转换为毫秒,请将其乘以 1000。
我正在使用 python 3.6.5 time.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)
根据我的机器给出了这个输出(所以我知道它在另一台机器上可能不同):
performance: 0.051401815000000003
1) 如何将上述值(以执行循环的运行时间为例的输出)转换为毫秒?我很困惑,因为文档说它 returns 以小数秒为单位的值。
2) fractional seconds
是什么意思?如果是秒的浮点数右边的小数,比如说11.56
秒,就是0.56
,那我怎么知道秒的值呢?
3) 我用它来计算运行时间或表演时间。我只需要函数花费的时间。
我已经用过了,所以请尝试 not
建议其他功能。请澄清我对我的习惯。
"in fractional seconds" 表示 "in seconds represented as a floating-point number"(相对于 C 的 time
,例如 returns 整数秒)。
因此,要将值转换为毫秒,请将其乘以 1000。