Profile Perl script with Devel::DProf

最近更新了一下feedman,使其可以打印每个feed最近更新的时间,然而运行的时候发现print.pl明显比cache.pl要耗费CPU资源,担心由于dreamhost的CPU时间限制而不能上线,于是便想做个profile看有没有优化的余地。

Perl有三个module可以做profile,分别是:

我使用了第一个,如下:

$ perl -d:DProf print.pl
$ dprofpp
Total Elapsed Time = 79.65801 Seconds
 User+System Time = 75.44801 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
48.8   36.81 36.815 418482   0.0000 0.0000  XML::Parser::Expat::eq_name
29.7   22.46 59.279 116011   0.0000 0.0001  XML::Parser::Expat::within_element
17.7   13.41 80.911 254813   0.0001 0.0003  XML::RSS::handle_char
4.18   3.154  4.948 610015   0.0000 0.0000  XML::Parser::Expat::generate_ns_name
3.85   2.903  2.903 527420   0.0000 0.0000  XML::Parser::Expat::current_element
3.27   2.469 85.910    153   0.0161 0.5615  XML::Parser::Expat::ParseString
3.13   2.360  2.360 309740   0.0000 0.0000  XML::Parser::Expat::namespace
2.38   1.794  1.794 345778   0.0000 0.0000  XML::Parser::Expat::GenerateNSName
1.49   1.123  2.080   1402   0.0008 0.0015  DateTime::new
0.79   0.597  0.610   5494   0.0001 0.0001  Params::Validate::_validate
0.67   0.509  2.503  24127   0.0000 0.0001  XML::RSS::handle_start
0.28   0.214 90.228    223   0.0010 0.4046  main::get_latest_update_date
0.26   0.194  0.433   2324   0.0001 0.0002  DateTime::_compare
0.22   0.169 86.556    205   0.0008 0.4222  XML::Feed::parse
0.16   0.119  0.177   1085   0.0001 0.0002  DateTime::Format::Mail::_parse_loose

可以看出时间都用在解析xml文件上了,google了一把发现XML::Parser已经是最快的了,没法子,只好到wiki.dreamhost.com上去看CPU时间限制的具体描述,原来每人每天不能超过60分钟,我想这对我来说足够了,至少可以先试试,反正也不会关站,不行再撤吧。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据