[SciPy-user] Very slow comparison of arrays of integers

Perry Greenfield perry at stsci.edu
Mon Jul 18 09:17:13 EDT 2005


Part of the problem may be due to the fact that your array is so small. 
For small numbers of values, lists are probably faster.  Try it with 
100,000 values and see what the comparison looks like. If it is still 
15 times slower than there is a problem with Numeric.

Perry Greenfield

On Jul 18, 2005, at 1:10 AM, Brian Granger wrote:

> Hello all,
>
> I have some code that is using scipy/numeric and one bottleneck in the 
> code consists of comparing arrays or lists of integers.  To my dismay, 
> I am finding that using Python lists is 15-20 times _faster_ than 
> using numeric array's for this.  The problem is that it seems that 
> there is no efficient way to compare arrays of integers.
>
> Here is code that clearly demonstrates this problem:
>
> from scipy import *
>
> def test_list(n):
>     a = range(100)
>     for i in range(n):
>         r = (a == a)
>
> def test_array(n):
>     a = array(range(100),Int)
>     for i in range(n):
>         r = allclose(a,a)
>
> The test_list code runs about 20 times as fast as the test_array code 
> that uses allclose().
>
> Is there any way of comparing to arrays of integers that would be as 
> fast or faster than using lists?  Any hints would be greatly 
> appreciated.
>
> Thanks
>
> Brian
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list