Return value while using cProfile

后端 未结 5 552
难免孤独
难免孤独 2020-12-13 06:59

I\'m trying to profile an instance method, so I\'ve done something like:

import cProfile

class Test():

    def __init__(self):
        pass

    def method         


        
5条回答
  •  误落风尘
    2020-12-13 07:36

    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

提交回复
热议问题