<?xml version="1.0" encoding="windows-1252"?>
<node id="136103" title="Re(2): Premature optimization" created="2002-01-03 20:38:41" updated="2005-07-27 15:41:39">
<type id="11">
note</type>
<author id="95145">
FoxtrotUniform</author>
<data>
<field name="doctext">
&lt;p&gt;My usual procedure for optimizing something is:&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;Profile it, to find out which part of the problem is
  taking the most time.  (Sometimes the problem's a single
  algorithm, in which case this isn't really necessary.)
 &lt;/li&gt;
 &lt;li&gt;Estimate the asymptotic bound of that bit of the
  problem.  (Yet another excellent real-world use for those
  icky awful theory courses you were forced to take in
  university. :-)&lt;/li&gt;
 &lt;li&gt;Try to make the algorithm faster.  Sometimes this just
  isn't possible; IIRC, you can't get a general sort on a
  single-processor machine faster than O(n log n).  But you
  can often simplify the problem: put a few restrictions on
  what you sort, and you can get down to O(n).  Nobody knows
  how to solve the travelling salesman problem in less than
  exponential time, but if you don't need a perfect
  solution, just one no worse than twice as bad as optimal,
  you can do it in polynomial (cubic, IIRC) time.&lt;/li&gt;
 &lt;li&gt;Repeat until you run out of relevant sub-problems.&lt;/li&gt;
 &lt;li&gt;If it still isn't fast enough, profile it again; this
  time, look for lines and functions that get executed most
  often, and try to slim those down.  If your program's data
  set is particularly small, this might be more important
  than step 2; then again, if n is small, your program's
  probably "fast enough".&lt;/li&gt;
&lt;/ol&gt;

&lt;tt&gt;-- &lt;br&gt;
:wq&lt;/tt&gt;</field>
<field name="root_node">
135852</field>
<field name="parent_node">
136073</field>
</data>
</node>
