[Numpy-discussion] Numpy Benchmarking

Keith Goodman kwgoodman at gmail.com
Tue Jun 27 21:18:51 CDT 2006


On 6/27/06, Keith Goodman <kwgoodman at gmail.com> wrote:
> On 6/27/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>
> > The numpy.dual library exists so you can use the SciPy calls if the
> > person has SciPy installed or the NumPy ones otherwise.  It exists
> > precisely for the purpose of seamlessly taking advantage of
> > algorithms/interfaces that exist in NumPy but  are improved in SciPy.
>
> That sounds very interesting. It would make a great addition to the
> scipy performance page:
>
> http://scipy.org/PerformanceTips
>
> So if I need any of the following functions I should import them from
> scipy or from numpy.dual? And all of them are faster?
>
> fft
> ifft
> fftn
> ifftn
> fft2
> ifft2
> norm
> inv
> svd
> solve
> det
> eig
> eigvals
> eigh
> eigvalsh
> lstsq
> pinv
> cholesky
>
> http://svn.scipy.org/svn/numpy/trunk/numpy/dual.py
>

Scipy computes the inverse of a matrix faster than numpy (except if
the dimensions of x are small). But scipy is slower than numpy for
eigh (I only checked for symmetric positive definite matrices):

from numpy import asmatrix, randn
from numpy.linalg import eigh as Neigh
from scipy.linalg import eigh as Seigh
import time

def test(N):

  x = asmatrix(randn(N,2*N))
  x = x * x.T

  t0 = time.time()
  eigval, eigvec = Neigh(x)
  t1 = time.time()

  t2 = time.time()
  eigval, eigvec = Seigh(x)
  t3 = time.time()

  print 'NumPy:', t1-t0, 'seconds'
  print 'SciPy:', t3-t2, 'seconds'

>> dual.test(10)
NumPy: 0.000217914581299 seconds
SciPy: 0.000226020812988 seconds

>> dual.test(100)
NumPy: 0.0123109817505 seconds
SciPy: 0.0321230888367 seconds

>> dual.test(200)
NumPy: 0.0793058872223 seconds
SciPy: 0.082535982132 seconds

>> dual.test(500)
NumPy: 0.59161400795 seconds
SciPy: 1.41600894928 seconds




More information about the Numpy-discussion mailing list