python性能分析器:line_profiler

代码:

import line_profiler
import sys

def test():
    for i in range(0, 10):
        print( i**2 )
    print("End of the function")


prof = line_profiler.LineProfiler(test) #pass in the function to profile

prof.enable() #start profiling
test()
prof.disable() #stop profiling

prof.dump_stats('test.prof')

prof.print_stats(sys.stdout) #print out the results

运行结果:

image





代码2:

from line_profiler import profile

@profile
def test():
    for i in range(0, 10):
        print( i**2 )
    print("End of the function")


test()

运行结果:

kernprof -l -v B02088_02_17.py


image





posted on 2024-07-30 10:36  Angry_Panda  阅读(79)  评论(0)    收藏  举报

导航