【问题标题】:How can I profile template performance in Template::Toolkit?如何在 Template::Toolkit 中分析模板性能?
【发布时间】:2010-09-22 04:46:56
【问题描述】:

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

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

【问题讨论】:

    标签: perl templates profiling template-toolkit


    【解决方案1】:

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

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

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

    -- info.html 于 2008 年 11 月 13 日星期四 09:33:26: cnt clk 用户 sys cuser csys 模板 1 0 0.06 0.00 0.00 0.00 动作.html 1 0 0.00 0.00 0.00 0.00 横幅.html 1 0 0.00 0.00 0.00 0.00 common_javascript.html 1 0 0.01 0.00 0.00 0.00 日期时间.html 1 0 0.01 0.00 0.00 0.00 diag.html 3 0 0.02 0.00 0.00 0.00 字段表 1 0 0.00 0.00 0.00 0.00 header.html 1 0 0.01 0.00 0.00 0.00 信息.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 推荐选项 1 0 0.01 0.00 0.00 0.00 关系块 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 表块 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 - 结尾

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

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

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 2011-01-18
      • 2011-01-30
      • 2013-01-27
      • 2012-03-12
      • 2013-05-17
      • 2018-12-08
      • 2021-03-22
      • 2016-08-10
      相关资源
      最近更新 更多