title: Tutorials on optimizing non-trivial Python applications with C extensions or Cython
body: <p>The Python community has published helpful reference material showing how to profile Python code, and the technical details of Python extensions in C or in <a href="http://cython.org/" rel="noreferrer">Cython</a>. I am still searching for tutorials which show, however, for non-trivial Python programs, the following:</p>
  
  <ol>
  <li>How to identify the hotspots which will benefit from optimization by conversion to a C extension</li>
  <li>Just as importantly, how to identify the hotspots which will <em>not</em> benefit from conversion to a C extension</li>
  <li>Finally, how to make the appropriate conversion from Python to C, either using the Python C-API or (perhaps even preferably) using Cython.</li>
  </ol>
  
  <p>A good tutorial would provide the reader with a methodology on how to reason through the problem of optimization by working through a complete example. I have had no success finding such a resource.</p>
  
  <p><strong>Do you know of (or have you written) such a tutorial?</strong></p>
  
  <p>For clarification, I'm not interested in tutorials that cover <em>only</em> the following:</p>
  
  <ul>
  <li>Using (c)Profile to profile Python code to measure running times</li>
  <li>Using tools to examine profiles (I recommend <a href="http://www.vrplumber.com/programming/runsnakerun/" rel="noreferrer">RunSnakeRun</a>)</li>
  <li>Optimizing by selecting more appropriate algorithms or Python constructs (e.g., sets for membership tests instead of lists); the tutorial should assume the algorithm and Python code is already optimal, and we are at a point where a C extension is the next logical step</li>
  <li>Recapitulating the <a href="http://docs.python.org/extending/" rel="noreferrer">Python documentation on writing C extensions</a>, which is already excellent as a reference but not useful as a resource for showing when and how to move from Python to C.</li>
  </ul>