python - How do I profile my time spent in library functions? -


when try profile class, unable break down time spent past each of own methods , functions.

for example, using cprofile, able following:

import numpy np import cprofile  class test_class:     def __init__(self, length, width):         self.length = length         self.width = width         self.populate()         return none      def populate(self):         self.array = np.random.randint(0, 3, (self.length, self.width))         return none      def add(self, additional_array):         self.array = np.add(self.array, additional_array)         return none   def test_function():     x, y = 3000, 2000     test_array = np.random.randint(0, 2, (x, y))     model_one = test_class(x, y)     model_one.add(test_array)  cprofile.run("test_function()") 

i given analysis:

         9 function calls in 0.214 seconds     ordered by: standard name     ncalls  tottime  percall  cumtime  percall filename:lineno(function)         1    0.002    0.002    0.214    0.214 <string>:1(<module>)         1    0.000    0.000    0.119    0.119 temp.py:11(populate)         1    0.020    0.020    0.020    0.020 temp.py:15(add)         1    0.002    0.002    0.212    0.212 temp.py:24(test_function)         1    0.000    0.000    0.119    0.119 temp.py:5(__init__)         1    0.000    0.000    0.214    0.214 {built-in method exec}         1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.profiler' objects}         2    0.190    0.095    0.190    0.095 {method 'randint' of 'mtrand.randomstate' objects} 

alternatively, using profilehooks able following:

@profile(immediate=true) def test_function():     x, y = 3000, 2000     test_array = np.random.randint(0, 2, (x, y))     model_one = test_class(x, y)     model_one.add(test_array)  test_function() 

and given analysis:

*** profiler results *** test_function (c:/users/mack/desktop/temp2.py:19) function called 1 times           7 function calls in 0.205 seconds     ordered by: cumulative time, internal time, call count     ncalls  tottime  percall  cumtime  percall filename:lineno(function)         1    0.000    0.000    0.205    0.205 temp.py:19(test_function)         2    0.185    0.093    0.185    0.093 {method 'randint' of 'mtrand.randomstate' objects}         1    0.000    0.000    0.113    0.113 temp.py:5(__init__)         1    0.000    0.000    0.113    0.113 temp.py:11(populate)         1    0.020    0.020    0.020    0.020 temp.py:15(add)         1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.profiler' objects}         0    0.000             0.000          profile:0(profiler) 

neither technique show how time spent in library functions. how can analysis shows me how time spent, instance, in numpy.add()?


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -