如何加快我的Perl程序? [英] How can I speed up my Perl program?

查看:89
本文介绍了如何加快我的Perl程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这确实是两个问题,但是它们是如此相似,为了简单起见,我想将它们放在一起:

This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:

  • 首先:在已经建立了Perl项目的情况下,除了普通的代码内优化之外,还有哪些不错的方法来加快它的速度?

  • Firstly: Given an established Perl project, what are some decent ways to speed it up beyond just plain in-code optimization?

第二:在Perl中从头开始编写程序时,有什么好的方法可以大大提高性能?

Secondly: When writing a program from scratch in Perl, what are some good ways to greatly improve performance?

对于第一个问题,想像一下您正在编写一个体面的项目,并且需要提高性能,但是您似乎无法通过重构/优化获得太多收益.在这种情况下,如果不使用C之类的方式重写它,您会怎么做呢?

For the first question, imagine you are handed a decently written project and you need to improve performance, but you can't seem to get much of a gain through refactoring/optimization. What would you do to speed it up in this case short of rewriting it in something like C?

请不要使用常规优化技术,除非它们是 Perl特定的.

Please stay away from general optimization techniques unless they are Perl specific.

我早些时候问过有关 Python 的问题,我认为将其用于其他方面可能会很好语言(如果对 psycho

I asked this about Python earlier, and I figured it might be good to do it for other languages (I'm especially curious if there are corollaries to psycho and pyrex for Perl).

推荐答案

请记住优化俱乐部的规则:

Please remember the rules of Optimization Club:

  1. 优化俱乐部的第一条规则 是,您没有优化.
  2. Optimization Club的第二条规则是,您不进行测量就不会进行优化.
  3. 如果您的应用运行速度高于基础传输协议,则优化结束.
  4. 一次一个因素.
  5. 没有marketoid,没有marketroid时间表.
  6. 测试将一直进行下去.
  7. 如果这是您在Optimization Club的第一个晚上,则必须编写一个测试用例.
  1. The first rule of Optimization Club is, you do not Optimize.
  2. The second rule of Optimization Club is, you do not Optimize without measuring.
  3. If your app is running faster than the underlying transport protocol, the optimization is over.
  4. One factor at a time.
  5. No marketroids, no marketroid schedules.
  6. Testing will go on as long as it has to.
  7. If this is your first night at Optimization Club, you have to write a test case.

因此,假设您确实有工作代码,请在 Devel :: NYTProf 下运行程序

So, assuming you actually have working code, run your program under Devel::NYTProf.

找到瓶颈.然后回到这里告诉我们它们是什么.

Find the bottlenecks. Then come back here to tell us what they are.

如果您没有拥有有效的代码,请先使其生效.您将要进行的最大的单项优化就是从不工作变为工作.

If you don't have working code, get it working first. The single biggest optimization you will ever make is going from non-working to working.

这篇关于如何加快我的Perl程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆