代码:
(1)
import cProfile
import re
cProfile.run('re.compile("foo|bar")')
运行结果:
(2)
import cProfile
def runRe():
import re
cProfile.runctx('re.compile("foo|bar")', None, locals())
runRe()
运行结果:
(3)
import cProfile
import re
def runRe():
re.compile("foo|bar")
prof = cProfile.Profile()
prof.enable()
runRe()
prof.create_stats()
prof.print_stats()
运行结果:
(4)
# import cProfile
import re
def runRe():
re.compile("foo|bar")
# prof = cProfile.Profile()
# prof.enable()
runRe()
# prof.create_stats()
# prof.print_stats()
运行结果:
python -m cProfile x.py -o x.profile
标签:stats,python,分析器,re,runRe,cProfile,prof,import From: https://www.cnblogs.com/devilmaycry812839668/p/18331498