为什么python中的line_profiler不能正确计算时间?
我不熟悉python中的line_profiler包。我是否读取的结果不正确,或者下面输出中的组件加起来不应该达到1.67554秒?相反,它们加起来是3.918秒(2426873微秒+1491105微秒)。谢谢为什么python中的line_profiler不能正确计算时间?,python,profiling,Python,Profiling,我不熟悉python中的line_profiler包。我是否读取的结果不正确,或者下面输出中的组件加起来不应该达到1.67554秒?相反,它们加起来是3.918秒(2426873微秒+1491105微秒)。谢谢 # test.py import numpy as np def tf(): arr = np.random.randn(3000,6000) np.where(arr>1,arr,np.nan) import test %lprun -f test.tf te
# test.py
import numpy as np
def tf():
arr = np.random.randn(3000,6000)
np.where(arr>1,arr,np.nan)
import test
%lprun -f test.tf test.tf()
Timer unit: 4.27654e-07 s
File: test.py
Function: tf at line 9
Total time: 1.67554 s
Line # Hits Time Per Hit % Time Line Contents
==============================================================
9 def tf():
10 1 2426873 2426873.0 61.9 arr = np.random.randn(3000,6000)
11 1 1491105 1491105.0 38.1 np.where(arr>1,arr,np.nan)
你误读了那里的时间;这些不是微秒 从: 时间:以计时器的单位执行该行所花费的总时间。在表格前面的标题信息中,您将看到一行“Timer unit:给出秒的转换系数。在不同的系统上可能会有所不同 我的。您的输出显示每个计时器单位约为0.428微秒。如果将单位与计时器单位值相乘,则总数匹配:
谢谢对不起,我应该仔细阅读这些文件。知道使用“计时器”而不仅仅是秒的背后是什么吗?我又看了一遍文件,但没有解释。我想大多数ppl是以秒为单位思考的,而不是“计时器单位”
>>> unit = 4.27654e-07
>>> 2426873 * unit + 1491105 * unit
1.675538963612