{numpy linalg lapack_lite dgeev {method 'randn' linalg py: (_assertfinite {method 'allof 'numpy ndarrayobjectssimilarlycalling %run - - cumulative cprof_example py has the same effect as the command-line approach aboveexcept you never have to leave ipython profiling function line-by-line in some cases the information you obtain from %prun (or another cprofile-based profile methodmay not tell the whole story about function' execution timeor it may be so complex that the resultsaggregated by function nameare hard to interpret for this casethere is small library called line_profiler (obtainable via pypi or one of the package management toolsit contains an ipython extension enabling new magic function %lprun that computes line-by-line-profiling of one or more functions you can enable this extension by modifying your ipython configuration (see the ipython documentation or the section on configuration later in this to include the following linea list of dotted module names of ipython extensions to load terminalipythonapp extensions ['line_profiler'line_profiler can be used programmatically (see the full documentation)but it is perhaps most powerful when used interactively in ipython suppose you had module prof_mod with the following code doing some numpy array operationsfrom numpy random import randn def add_and_sum(xy)added summed added sum(axis= return summed def call_function() randn( randn( return add_and_sum(xyif we wanted to understand the performance of the add_and_sum function%prun gives us the followingin [ ]%run prof_mod in [ ] randn( in [ ] randn( in [ ]%prun add_and_sum(xy function calls in seconds ordered byinternal time ncalls tottime percall cumtime percall filename:lineno(function prof_mod py: (add_and_sum ipythonan interactive computing and development environment www it-ebooks info