如何在Template :: Toolkit中分析模板性能?

时间:2008-11-13 17:04:38

标签: perl templates profiling template-toolkit

使用Template::Toolkit时,对各种模板的效果进行基准测试的最佳方法是什么?

我想要一些能够分解处理每个块或模板文件花费多少CPU /系统时间的东西,不包括处理其他模板所花费的时间。例如,Devel::DProf对此无用,因为它只是告诉我在模块模块的各种内部方法中花了多少时间。

1 个答案:

答案 0 :(得分:15)

事实证明,谷歌搜索 template :: toolkit profiling 会产生最好的结果,来自November 2005 by Randal Schwartz的文章。由于版权问题,我无法在此处复制和粘贴任何文章,但只需说明您只需获取his source并将其用作模板之后的模块,如下所示:

use Template;
use My::Template::Context;

当你的脚本运行时,你会得到这样的输出到STDERR:

-- info.html at Thu Nov 13 09:33:26 2008:
cnt clk   user    sys  cuser   csys template
  1   0   0.06   0.00   0.00   0.00 actions.html
  1   0   0.00   0.00   0.00   0.00 banner.html
  1   0   0.00   0.00   0.00   0.00 common_javascript.html
  1   0   0.01   0.00   0.00   0.00 datetime.html
  1   0   0.01   0.00   0.00   0.00 diag.html
  3   0   0.02   0.00   0.00   0.00 field_table
  1   0   0.00   0.00   0.00   0.00 header.html
  1   0   0.01   0.00   0.00   0.00 info.html
  1   0   0.01   0.01   0.00   0.00 my_checklists.html
  1   0   0.00   0.00   0.00   0.00 my_javascript.html
  1   0   0.00   0.00   0.00   0.00 qualifier.html
 52   0   0.30   0.00   0.00   0.00 referral_options
  1   0   0.01   0.00   0.00   0.00 relationship_block
  1   0   0.00   0.00   0.00   0.00 set_bgcolor.html
  1   0   0.00   0.00   0.00   0.00 shared_javascript.html
  2   0   0.00   0.00   0.00   0.00 table_block
  1   0   0.03   0.00   0.00   0.00 ticket.html
  1   0   0.08   0.00   0.00   0.00 ticket_actions.html
-- end

请注意列出了块以及单独的文件。

这是恕我直言,比CPAN模块Template::Timer更有用。

相关问题