听来Devel::DProf这个模块不错啵,找时间试试。 :-) agentzh wrote: > 2009/8/25 imxae <[email protected] <mailto:[email protected]>> > > 不知道是什么会使perl程序运行较慢呢? > > 如,不正确的变量引用,或是字符串操作等等... > > > 一般是更宏观的算法和设计上的问题导致 perl 脚本不必要地运行缓慢。通过 > Devel::DProf 这样的模块可以发现许多导致代码变慢的代码“热点”。这一篇东 > 西值得一读: > > http://www.perl.com/pub/a/2004/06/25/profiling.html > > 我最近就遇到一个活生生的例子。我通过 Devel::DProf 模块定位到我的 > VDOM.pm 模块下面一行代码占用了太多的 CPU 时间: > > if (substr($txt, 0, 1) ne '_') { ... } > > 因为它所在的 new 方法被调用的次数非常之多,所以累积起来就相当可观。然 > 后我尝试将之替换为下面这一行: > > if ($txt !~ /^_/) { ... } > > 结果 new 方法立马从 Devel::DProf 的热点排行榜中消失了,整个抽取器测试 > 集的运行时间也从 43 秒下降到 38 秒 :) (在 perl optree 级别上解释这种 > 区别应当也是很有教益的,anyone?) > > chromatic 的日志( http://use.perl.org/~chromatic/journal > <http://use.perl.org/%7Echromatic/journal> )中有不少关于 parrot 虚拟 > 机里的微小但效果显著的优化案例,很有趣味,不过多是 C 级别上的了,呵呵。 > > 日后有机会我也想在 perlchina 聚会上分享我在 Perl 代码 profiling 和优化 > 上的一点点小经验。。。呵呵 > > Cheers, > -agentzh > >
-- Perl乐事 -- http://www.perlersh.org 我的博客 -- http://www.perlersh.org/blog.html --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
