質問

I am new to the line_profiler package in python. Am I reading the result incorrectly, or shouldn't the components in the output below add up to 1.67554 seconds? Instead, they add up to 3.918 seconds (2426873 microseconds + 1491105 microseconds). Thanks!

# 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)
役に立ちましたか?

解決

You misread the time there; those are not microseconds.

From the documentation:

Time: The total amount of time spent executing the line in the timer's units. In the header information before the tables, you will see a line "Timer unit:" giving the conversion factor to seconds. It may be different on different systems.

Emphasis mine. Your output shows each Timer unit is about 0.428 microseconds. The totals match if you multiply the units with the Timer unit value:

>>> unit = 4.27654e-07
>>> 2426873 * unit + 1491105 * unit
1.675538963612
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top