cheun 发表于 2017-5-18 08:56:51

用Devel::NYTProf 优化perl脚本性能

  前几天发一下一个脚本运行非常慢,使用time只能知道总的时间,却无法确认原因,发现Devel::NYTProf是个很不错的工具。
  如果你有root权限,则:
  perl -MCPAN -e shell
>installJSON::Any(不安这个东东,在nyt生成html的时候会报warning,不是必须的)
>installDevel::NYTProf
  如果你没有root权限,那么:

[*]在home目录下新建一个文件夹,比如 /home/username/perl.local
[*]从http://search.cpan.org/~timb/Devel-NYTProf-4.06/lib/Devel/NYTProf.pm下载原始文件到这个文件夹
[*]解压缩,然后make
[*]找到Makefile里面的PREFIX,将值修改为 /home/username/perl.local
[*]在 /home/username/perl.local下面新建一个local目录
[*]然后make install,完成安装
[*]/home/username/perl.local下会多出bin,local,share目录
[*]修改环境变量,export PERL5LIB="$PERL5LIB:/home/username/perl.local/local/lib/perl/5.8.4"
  运行perl -d:NYTProf /home/username/url_parser.pl,会在当前路径下生成nytprof.out
  运行 /home/username/perl.local/bin/nytprofhtml nytprof.out生成web页面。



  看看那个函数最耗时


  看看那个语句最耗时

  【参考】

[*]http://blog.sina.com.cn/s/blog_04268f4b0100moi9.html
[*]http://augustinalareina.wordpress.com/2011/02/05/getting-started-with-develnytprof/
页: [1]
查看完整版本: 用Devel::NYTProf 优化perl脚本性能