[Numpy-discussion] numpy vs numeric benchmarks

Eric Jonas jonas at mwl.mit.edu
Fri Jun 2 08:58:50 EDT 2006


Hello! I've been using numeric for a while, and the recent list traffic
prompted me to finally migrate all my old code. On a whim, we were
benchmarking numpy vs numeric and have been lead to the conclusion that
numpy is at least 50x slower; a 1000x1000 matmul takes 16 sec in numpy
but 300 ms in numeric. 

Now, of course, I don't believe this, but I can't figure out what we're
doing wrong; I'm not the only person who has looked at this code, so can
anyone tell me what we're doing wrong? 

We run both benchmarks twice to try and mitigate any start-up and cache
effects. This is with debian-amd64's packaged numeric 24.2-2 and a
locally built numpy-0.9.8. 

/usr/bin/python
import time
import numpy
import random
import Numeric


def numpytest():
   N = 1000
   x = numpy.zeros((N,N),'f')
   y = numpy.zeros((N,N),'f')
   
   for i in range(N):
      for j in range(N):
         x[i, j] = random.random() 
         y[i, j] = random.random()
   
   t1 = time.clock()
   z = numpy.matrixmultiply(x, y)
   t2 = time.clock()
   
   print (((t2 - t1)*1000))



def numerictest():
   N = 1000

   x = Numeric.zeros((N,N),'f')
   y = Numeric.zeros((N,N),'f')
   
   for i in range(N):
      for j in range(N):
         x[i, j] = random.random() 
         y[i, j] = random.random()

   t1 = time.clock()
   z = Numeric.matrixmultiply(x, y)
   t2 = time.clock()
   
   print (((t2 - t1)*1000))

numerictest()
numpytest()
numpytest()
numerictest()

on our hardware a call to numerictest() takes 340 ms and a numpytest
takes around 13 sec (!). 

Any advice on what we're doing wrong would be very helpful. 
			...Eric






More information about the NumPy-Discussion mailing list