title: Scipy's curve_fit / leastsq become slower when given the Jacobian?
body: <p>So I wad reading the documentation about <code>curve_fit</code> <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow">here</a>. It contains the following example:</p>
  
  <pre><code>import numpy as np
  import scipy.optimize as so
  
  def func(x, a,b,c ):
      return a * np.exp(-b * x) + c
  
  a,b,c = 2.5, 1.3, 0.5
  nx = 500
  noiseAlpha = 0.5
  #
  xdata = np.linspace(0, 4, nx)
  y = func(xdata, a,b,c)
  ydata = y + noiseAlpha * np.random.normal(size=len(xdata))
  </code></pre>
  
  <p>If I call <code>curve_fit</code> now, it will approximate the derivatives since I didn't provide anything. Let's time it:</p>
  
  <pre><code>%%timeit
  popt, pcov = so.curve_fit(func, xdata, ydata )
  1000 loops, best of 3: 787 µs per loop
  </code></pre>
  
  <p>In fact <code>curve_fit</code> calls <code>leastsq</code> <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html#scipy.optimize.leastsq" rel="nofollow">(doc here)</a>, which accepts a <code>Dfun</code> argument for computing the Jacobian. So I did this: </p>
  
  <pre><code>def myDfun( abc, xdata, ydata, f ) :
      a,b,c = abc
      ebx = np.exp(-b * xdata)
      res = np.vstack( ( ebx, a * -xdata * ebx, np.ones(len(xdata)) ) ).T
      return res
  </code></pre>
  
  <p>And I timed it again: </p>
  
  <pre><code>%%timeit
  popt, pcov = so.curve_fit(func, xdata, ydata, Dfun=myDfun )
  1000 loops, best of 3: 858 µs per loop
  </code></pre>
  
  <p>Uh? Using the Jacobian is slower than approximating it? Did i do something wrong?</p>