16.8.4 限制报告内容 可以按函数限制输出。下面这个版本只显示fib()和fib_seq()性能的有关信息,这里使用一个正则表达式来匹配所需的filename:lineno(function)值。
import profile
import pstats
from profile_fibonacci_memoized
import fib
,fib_seq
stats
= pstats
.Stats
('profile_stats_0.stats')
for i
in range(1,5):
stats
.add
('profile_stats_{}.stats'.format(i
))
stats
.strip_dirs
()
stats
.sort_stats
('cumulative')
stats
.print_stats
('\(fib')
这个正则表达式包含一个字面量左括号((),以匹配位置值的函数名部分。