dipy logo

Site Navigation

NIPY Community

dipy.core.profile

Class for profiling cython code

class dipy.core.profile.Profiler(call=None, *args)

Profile python/cython files or functions

If you are profiling cython code you need to add # cython: profile=True on the top of your .pyx file

and for the functions that you do not want to profile you can use this decorator in your cython files

@cython.profile(False)

Parameters:

caller : file or function call

args : function arguments

References

http://docs.cython.org/src/tutorial/profiling_tutorial.html http://docs.python.org/library/profile.html http://packages.python.org/line_profiler/

Examples

from dipy.core.profile import Profiler import numpy as np p=Profiler(np.sum,np.random.rand(1000000,3)) fname=’test.py’ p=Profiler(fname) p.print_stats(10) p.print_stats(‘det’)

Attributes

stats function, stats.print_stats(10) will prin the 10 slower functions  

Methods

print_stats([N]) Print stats for profiling
print_stats(N=10)

Print stats for profiling

You can use it in all different ways developed in pstats for example print_stats(10) will give you the 10 slowest calls or print_stats(‘function_name’) will give you the stats for all the calls with name ‘function_name’

Parameters:N : stats.print_stats argument