总结 Perl 是一个强大的语言,但它仍不能防止编程者的差的设计。一个失误可能是因为选择了错误的数据结构或者算法。通过使用一些简单的复杂度理论,就有可能优化代码而提升速度。 我这里只是接触了 O 符号的表层和复杂度理论。在数学和计算机的更深层次中还有很多对它的研究。但希望这里提到的能够帮助你掌握最基本的工具。
正如第二个例子所示,你不必为优化而耗费过多时间来考虑。过度优化并不值得。
更多的信息 Google http://www.google.com/search?q=big-O+complexity Introduction to the Theory of Computation Part Three of Sipser, Michael. “Introduction to the Theory of Computation”. PWS Publishing Company. Boston, MA. 1997. Algorithms and Complexity, Internet Edition http://www.cis.upenn.edu/~wilf/AlgComp2.html 特别感谢 Walt Mankowski Perl.com Compilation Copyright ?? 1998-2000 O’Reilly & Associates, Inc.