编辑器
import cProfile, pstats def work(): s = 0 for i in range(20000): s += i*i return s pr = cProfile.Profile() pr.enable() work() pr.disable() pstats.Stats(pr).strip_dirs().sort_stats("time").print_stats(5)
2 function calls in 0.001 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.001 0.001 0.001 0.001 prog.py:3(work)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}