def add_and_sum(x, y):
    added = x + y
    summed = added.sum(axis=1)
    return summed

def call_function():
    x = np.random.randn(1000, 1000)
    y = np.random.randn(1000, 1000)
    return add_and_sum(x, y)
x = np.random.randn(3000, 3000)
y = np.random.randn(3000, 3000)
%lprun -f add_and_sum add_and_sum(x,y)
Timer unit: 1e-06 s

Total time: 0.104848 s
File: <ipython-input-1-d7add890ce66>
Function: add_and_sum at line 1

Line #      Hits         Time  Per Hit   % Time  Line Contents  
==============================================================  

     1                                           def add_and_sum(x, y):
     2         1        87601  87601.0     83.6      added = x + y
     3         1        17244  17244.0     16.4      summed = added.sum(axis=1)
     4         1            3      3.0      0.0      return summed
%lprun -f add_and_sum call_function()
Timer unit: 1e-06 s

Total time: 0.009731 s
File: <ipython-input-1-d7add890ce66>
Function: add_and_sum at line 1

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     1                                           def add_and_sum(x, y):
     2         1         7852   7852.0     80.7      added = x + y
     3         1         1875   1875.0     19.3      summed = added.sum(axis=1)
     4         1            4      4.0      0.0      return summed
%lprun -f add_and_sum -f call_function call_function()
Timer unit: 1e-06 s

Total time: 0.009769 s
File: <ipython-input-1-d7add890ce66>
Function: add_and_sum at line 1

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     1                                           def add_and_sum(x, y):
     2         1         7939   7939.0     81.3      added = x + y
     3         1         1828   1828.0     18.7      summed = added.sum(axis=1)
     4         1            2      2.0      0.0      return summed

Total time: 0.176444 s
File: <ipython-input-1-d7add890ce66>
Function: call_function at line 6

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     6                                           def call_function():
     7         1        88332  88332.0     50.1      x = np.random.randn(1000, 1000)
     8         1        78309  78309.0     44.4      y = np.random.randn(1000, 1000)
     9         1         9803   9803.0      5.6      return add_and_sum(x, y)


Line profiling with %lprun in IPython

Reviewed by on

Rating: 5 out of 5

Write a comment:

*

Your email address will not be published.

© 2014 In R we trust.
Top
Follow us: