1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
7
<year>2001</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
24
<title>Introduction</title>
25
<prepared>Bjorn Gustavsson</prepared>
27
<date>2007-11-21</date>
29
<file>introduction.xml</file>
33
<title>Purpose</title>
35
<quote><p>Premature optimization is the root of all evil. -- D.E. Knuth</p></quote>
37
<p>Efficient code can be well-structured and clean code, based on
38
on a sound overall architecture and sound algorithms.
39
Efficient code can be highly implementation-code that bypasses
40
documented interfaces and takes advantage of obscure quirks in
41
the current implementation.</p>
43
<p>Ideally, your code should only contain the first kind of efficient
44
code. If that turns out to be too slow, you should profile the application
45
to find out where the performance bottlenecks are and optimize only the
46
bottlenecks. Other code should stay as clean as possible.</p>
48
<p>Fortunately, compiler and run-time optimizations introduced in
49
R12B makes it easier to write code that is both clean and
50
efficient. For instance, the ugly workarounds needed in R11B and earlier
51
releases to get the most speed out of binary pattern matching are
52
no longer necessary. In fact, the ugly code is slower
53
than the clean code (because the clean code has become faster, not
54
because the uglier code has become slower).</p>
56
<p>This Efficiency Guide cannot really learn you how to write efficient
57
code. It can give you a few pointers about what to avoid and what to use,
58
and some understanding of how certain language features are implemented.
59
We have generally not included general tips about optimization that will
60
work in any language, such as moving common calculations out of loops.</p>
64
<title>Prerequisites</title>
65
<p>It is assumed that the reader is familiar with the Erlang
66
programming language and concepts of OTP.</p>