title: Numba and Cython aren't improving the performance compared to CPython significantly, maybe I am using it incorrectly?
body: <p>BIG EDIT:</p>
  
  <p>================</p>
  
  <p>For the sake of clarity, I am removing the old results and replace it by the more recent results. The question is still the same: Am I using both Cython and Numba correctly, and what improvements to the code can be made? (I have a newer and more bare-bones temporary IPython notebook with all the code and results <a href="http://nbviewer.ipython.org/github/rasbt/One-Python-benchmark-per-day/blob/master/ipython_nbs/scratch/python_cython_numba.ipynb?create=1" rel="noreferrer">here</a>)</p>
  
  <h1>1)</h1>
  
  <p>I think I figured out why there was initially no difference between Cython, Numba, and CPython: It was because I fed them </p>
  
  <p>numpy arrays as input:</p>
  
  <pre><code>x = np.asarray([x_i*np.random.randint(8,12)/10 for x_i in range(n)])
  </code></pre>
  
  <p>instead of lists:  </p>
  
  <pre><code>x = [x_i*random.randint(8,12)/10 for x_i in range(n)]
  </code></pre>
  
  <h2>Benchmark using Numpy arrays as data input</h2>
  
  <p><img src="https://i.stack.imgur.com/Qk56o.png" alt="enter image description here"></p>
  
  <h2>Benchmark using Python lists as input</h2>
  
  <p><img src="https://i.stack.imgur.com/ZnCPh.png" alt="enter image description here"></p>
  
  <h1>2)</h1>
  
  <p>I replaced the <code>zip()</code> function by explicit loops, however, it didn't make much of a difference. The code would be:</p>
  
  <h3>CPython</h3>
  
  <pre><code>def py_lstsqr(x, y):
      """ Computes the least-squares solution to a linear matrix equation. """
      len_x = len(x)
      x_avg = sum(x)/len_x
      y_avg = sum(y)/len(y)
      var_x = 0
      cov_xy = 0
      for i in range(len_x):
          temp = (x[i] - x_avg)
          var_x += temp**2
          cov_xy += temp*(y[i] - y_avg)
      slope = cov_xy / var_x
      y_interc = y_avg - slope*x_avg
      return (slope, y_interc) 
  </code></pre>
  
  <h3>Cython</h3>
  
  <pre><code>%load_ext cythonmagic
  
  %%cython
  def cy_lstsqr(x, y):
      """ Computes the least-squares solution to a linear matrix equation. """
      cdef double x_avg, y_avg, var_x, cov_xy,\
           slope, y_interc, x_i, y_i
      cdef int len_x
      len_x = len(x)
      x_avg = sum(x)/len_x
      y_avg = sum(y)/len(y)
      var_x = 0
      cov_xy = 0
      for i in range(len_x):
          temp = (x[i] - x_avg)
          var_x += temp**2
          cov_xy += temp*(y[i] - y_avg)
      slope = cov_xy / var_x
      y_interc = y_avg - slope*x_avg
      return (slope, y_interc)
  </code></pre>
  
  <h3>Numba</h3>
  
  <pre><code>from numba import jit
  
  @jit
  def numba_lstsqr(x, y):
      """ Computes the least-squares solution to a linear matrix equation. """
      len_x = len(x)
      x_avg = sum(x)/len_x
      y_avg = sum(y)/len(y)
      var_x = 0
      cov_xy = 0
      for i in range(len_x):
          temp = (x[i] - x_avg)
          var_x += temp**2
          cov_xy += temp*(y[i] - y_avg)
      slope = cov_xy / var_x
      y_interc = y_avg - slope*x_avg
      return (slope, y_interc)
  </code></pre>