[Numpy-discussion] Numpy array performance issue

Bruno Santos bacmsantos at gmail.com
Wed Feb 24 10:55:51 EST 2010


Hello everyone,

I am using numpy arrays whenever I demand performance from my
algorithms. Nevertheless, I am having a performance issue at the moment
mainly because I am iterating several times over numpy arrays. Fot that
reason I decided to use timeit to see the performance of different versions
of the same procedure. What surprised me was that in fact Python lists are
performing almost ten times faster than numpy. Why is this happening.
My test code is this:

list1 = [random.randint(0,20) for i in xrange(100)]
 list2 = numpy.zeros(100,dtype='Int64')
for i in xrange(100):list2[i]=random.randint(0,20)
def test1(listx):

return len([elem for elem in list if elem >=10])

t = timeit.Timer("test1(list1)","from __main__ import *")
>>> t.timeit()
6.4516620635986328
t = timeit.Timer("test1(list2)","from __main__ import *")
>>> t.timeit()
76.807533979415894

Thanks in advance,
Bruno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100224/d801be93/attachment.html>


More information about the NumPy-Discussion mailing list