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

查看:25
本文介绍了如何加速我的 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 特定的.

我之前问过这个关于 Python 的问题,我认为对其他人这样做可能会很好语言(我特别想知道 psychopyrex for Perl).

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. 没有marketroids,没有marketroid时间表.
  6. 只要有必要,测试就会继续.
  7. 如果这是您在 Optimization Club 的第一个晚上,您必须编写一个测试用例.

因此,假设您确实有工作代码,请在 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天全站免登陆