title: Cython : pure C loop optimization
body: <p>Quoting the <a href="http://docs.cython.org/src/userguide/language_basics.html#integer-for-loops">Cython documentation</a>:</p>
  
  <pre><code>Cython recognises the usual Python for-in-range integer loop pattern:
      for i in range(n):
          ...
  If i is declared as a cdef integer type, it will optimise this into a pure C loop
  </code></pre>
  
  <p>I wrote two versions of a simple Cython function, one using the Python <code>range</code>, the other one using the <code>for-from</code> Pyrex notation (which is supposed to be deprecated):</p>
  
  <pre><code> def loop1(int start, int stop, int step):
      cdef int x, t = 0
      for x in range(start, stop, step):
          t += x
      return t
  
  def loop2(int start, int stop, int step):
      cdef int x, t = 0
      for x from start &lt;= x &lt; stop by step:
          t += x
      return t
  </code></pre>
  
  <p>By looking at <code>.c</code>file, I noticed that the two loops have been processed in a very different way:</p>
  
  <p>The first one is actually creating a Python range, using Python objects. And it comes with 50 lines of unnecessary Python-to-C C-to-Python stuff.</p>
  
  <p>The second one has been optimized into a nice pure C loop:</p>
  
  <pre><code>__pyx_t_1 = __pyx_v_stop;
  __pyx_t_2 = __pyx_v_step;
  for (__pyx_v_x = __pyx_v_start; __pyx_v_x &lt; __pyx_t_1; __pyx_v_x+=__pyx_t_2) {
  </code></pre>
  
  <p>Am I missing something or is it a bug that I should report?</p>