[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] array search



Derek Simkowiak wrote:

> >The problem at hand is "finding all indexes that are not 0", so you 
> >obviously do have to iterate through the whole array to find them... 
> >whether or not you explicitly use 'for' to do it.
> 
> 	With large data sets, there can be a significant speed difference 
> 	between 'for' and using map() or filter().

map() could be just as fast as a custom C function in the case of just
testing for "not 0". As you can use the operator.truth function in the
map call and using a C function (which all things in the operator module
are) with map means it all runs in C.
 
> 	The best option (if speed is paramount) is to pass the list to a 
> 	custom C function that does the looping.  I have used SWIG to 
> 	interface C to Python, and posters have mentioned other C-to-Python 
> 	helpers on this list.

For simple things interface generators like SWIG can be overkill. Just
coding it up in pythonic-C can be much easier.

-- 

John Eikenberry
[jae@zhar.net - http://zhar.net]
______________________________________________________________
"Perfection (in design) is achieved not when there is nothing more to add,
 but rather when there is nothing more to take away."
                                        -- Antoine de Saint-Exupery