I\'m trying to profile an instance method, so I\'ve done something like:
import cProfile class Test(): def __init__(self): pass def method
An option for any arbitrary code:
import cProfile, pstats, sys pr = cProfile.Profile() pr.enable() my_return_val = my_func(my_arg) pr.disable() ps = pstats.Stats(pr, stream=sys.stdout) ps.print_stats()
Taken from https://docs.python.org/2/library/profile.html#profile.Profile